我已经从
创建了一个AppleScript软件包 -main.app
on run
set appAlias to POSIX path of (path to resource "MyApp.app")
set cmnd to appAlias & "Contents/MacOs/MyApp &"
display dialog "You're going to launch" & cmnd buttons {"Ok"}
do shell script cmnd with administrator privileges
end run
MyApp.app
位于main.app/Contents/Resources
当我启动main.app
时,它会在显示对话框后立即退出,并在不启动username
的情况下询问password
和MyApp.app
。
我做错了什么?
答案 0 :(得分:3)
如果路径中有任何空格,则可能存在一个问题,那么路径基本上是不正确的。因此,您应始终使用“引用形式”来确保正确考虑空格和其他路径字符。试试这个......
on run
set appAlias to POSIX path of (path to resource "MyApp.app")
set cmnd to appAlias & "Contents/MacOs/MyApp"
display dialog "You're going to launch" & cmnd buttons {"Ok"}
do shell script (quoted form of cmnd & " &") with administrator privileges
end run
另外,我认为您需要确定MyApp.app中的unix可执行文件的名称。大多数AppleScript应用程序内部都有“applet”,而不是应用程序的名称。所以仔细检查一下。你可能需要这个......
set cmnd to appAlias & "Contents/MacOS/applet"
答案 1 :(得分:1)
尝试:
on run
set appAlias to POSIX path of (path to resource "MyApp.app")
display dialog "You're going to launch" & appAlias buttons {"Ok"}
tell application "System Events" to open appAlias
end run
修改
on run
set appAlias to POSIX path of (path to resource "MyApp.app")
display dialog "You're going to launch" & appAlias buttons {"Ok"}
do shell script "open " & quoted form of appAlias with administrator privileges
end run
答案 2 :(得分:0)
我的剧本中有一个愚蠢的错误。我需要写“MacOS”而不是“MacOs” 这是允许我的应用程序在受限区域中创建文件的脚本:
on run
set appAlias to POSIX path of (path to resource "MyApp.app")
set cmnd to appAlias & "Contents/MacOS/MyApp"
display dialog "You're going to launch" & cmnd buttons {"Ok"}
do shell script cmnd with administrator privileges
end run