背景:我正在尝试编写一个简单的 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
答案1
尝试:
set UnixPath to POSIX path of ((path to me as text) & "::")
答案2
您应该从“Tell Block”内运行脚本,例如:
tell application "Finder"
get path to me
set a to container of the result
return (a as alias)
-- Or just get the name of the Parent Container like;
set b to name of a
return b
end tell