英文:
Open With Application: How to detect filename in go
问题
我在我的Mac上创建了一个Go应用程序,可以读取/写入*.myext文件。可执行文件被打包到一个名为"MyApp"的Bundle中。
我可以启动MyApp,然后读取/写入*.myext文件,这个是可以的。
我的问题是:如果我通过"打开方式" > "MyApp"(通常是右键单击)打开test.myext文件,如何检测文件名?
我尝试从os.Args中读取文件名,但文件名不在其中。
有办法吗?
谢谢你的帮助!
Leo
英文:
I have created a go application on my mac that reads/writes from files *.myext. The executable was packed into an a Bundle called "MyApp".
I can start MyApp and then read/write *.myext files, that works.
My question is: how to detect the filename if I am opening e.g. test.myext by Open With > MyApp (usually right mouse button)?
I have tried to read the file name from os.Args, but the file name is not in there.
Is there a way?
Thank you for your help!
Leo
答案1
得分: 1
看起来通过“打开方式”启动的程序无法接收到它所调用的文件的名称,而是必须使用“Apple事件”来获取它,就像这里接受的答案所描述的那样。
因此,我担心目前解决这个问题的唯一方法是使用cgo
;可能是按照这些步骤进行操作。
英文:
Looks like a program started via "Open With" does not receive the name of the file it has been invoked on but rather has to obtain it using "Apple events" as described in the accepted answer here.
I am thereby afraid currently the only way to solve the problem would be to use cgo
; may be along these lines.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论