背景:我正在尝试编写一个简单的applescript应用程序,它将启动一个tcl应用程序,但是我陷入了脚本的第一部分。
我需要获取applescript路径的父文件夹。当我运行此代码时:
set LauncherPath to path to me
set ParentPath to container of LauncherPath
...我得到这个错误:
error "Can’t get container of alias \"Macintosh HD:Users:simon:Downloads:folder with spaces:CrossFire-master:CrossFire Launcher for Mac.app:\"." number -1728 from container of alias "Macintosh HD:Users:simon:Downloads:folder with spaces:CrossFire-master:CrossFire Launcher for Mac.app:"
阅读此答案后,我尝试了以下方法:
set LauncherPath to path to me
set RealLauncherPath to first item of LauncherPath
set ParentPath to container of RealLauncherPath
...但是我得到了这个错误:
error "Can’t get item 1 of alias \"Macintosh HD:Users:simon:Downloads:folder with spaces:CrossFire-master:CrossFire Launcher for Mac.app:\"." number -1728 from item 1 of alias "Macintosh HD:Users:simon:Downloads:folder with spaces:CrossFire-master:CrossFire Launcher for Mac.app:"
任何帮助或想法,不胜感激。提前致谢!
PS一旦我解决了以上问题,完整的脚本将如下所示:
set LauncherPath to path to me
set RealLauncherPath to first item of LauncherPath
set ParentPath to container of RealLauncherPath
set UnixPath to POSIX path of ParentPath
set launcherCrossFire to "/usr/local/bin/wish " & UnixPath & "/CrossFire.tcl > /dev/null &" -- creat command to launch CrossFire
do shell script launcherCrossFire
更新:这是包含以下答案的工作脚本:
set UnixPath to POSIX path of ((path to me as text) & "::") --get path to parent folder
set LaunchCrossFire to "/usr/local/bin/wish '" & UnixPath & "CrossFire.tcl' > /dev/null 2>&1 &" -- creat command to launch CrossFire
do shell script LaunchCrossFire -- run command