我将AppleScript保存为应用程序。首次运行时,它会询问用户是否要将其移动到“应用程序”文件夹。我希望能够做的是,在它被移动后,让脚本自行退出然后重新打开。
显然我不能说
tell me to quit
tell me to activate
...因为它会在quit
命令之后停止运行。
有什么建议吗?
答案 0 :(得分:0)
只需从脚本内部运行脚本,并确保使用return返回当前运行的脚本(如果它是脚本的最后一行,则可以跳过实际的返回命令
-- do stuff
display dialog "Here I am again"
-- set alias to the script
-- run the script
set myScript to path to me
run script myScript
-- end current iteration
return
您可以通过取消对话框来突破此脚本,但您可能想要设置条件以检查是否再次运行脚本。
答案 1 :(得分:0)
我在这里是怎么做到的。基本上,您检查应用程序是否从Applications文件夹运行。如果不是,请将其移动到那里,打开另一个实例,然后退出。似乎完美无瑕地工作。开头的激活是因为应用程序似乎并不总是将自己移到前台:
ng-change
答案 2 :(得分:0)
我在做什么。
首先我通过在终端中运行以下命令来启用(这只需要执行一次)
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist
然后我有以下脚本
display dialog "running"
set mypath to POSIX path of (path to me)
set lun to open for access POSIX file "/tmp/springboard" with write permission
write "open " & mypath & linefeed to lun
close access lun
do shell script "at -f /tmp/springboard +1 minute"
quit