打开应用程序:如何在Go中检测文件名

huangapple go评论96阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2015年4月27日 20:54:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/29896408.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定