0

我创建了一个 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后立即退出。我究竟做错了什么?usernamepasswordMyApp.app

4

3 回答 3

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"
于 2013-07-14T08:51:33.183 回答
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
于 2013-07-13T16:51:34.067 回答
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
于 2013-07-14T14:10:17.087 回答