【发布时间】:2014-10-17 16:32:45
【问题描述】:
我正在编写一个可以为我打开和关闭应用程序的脚本。基本上,我输入一个应用程序名称,然后它会打开应用程序。唯一的事情是,如果未找到该应用程序,它会引发错误并退出。我想让脚本只显示一个对话框,上面写着“找不到应用程序”。
这是我目前所拥有的:
if userInput contains "Activate " then set {TID, text item delimiters} to {text item delimiters, {"Activate "}}
if length of userInput is less than or equal to 1 then say (resultString as string)
if length of userInput is greater than or equal to 2 then set resultString to text item 2 of userInput
set openApp to (resultString as string)
if userInput contains "Activate " then set text item delimiters to TID
if userInput contains "Activate " then tell application (openApp as string) to activate
顺便说一句,这只是我脚本的一个 sn-p,这就是为什么这里有一些未定义的变量。
我试过了:
set appList to do shell script "cd /Applications; ls"
if openApp is not in appList then display dialog "App not found"
嗯,Applescript 语法有时很烦人。
谢谢。
【问题讨论】:
-
但是您没有看到一个弹出窗口询问“xyz 在哪里?”
-
我愿意,但如果我按下取消键,我会收到一条奇怪的消息
标签: macos applescript osx-mavericks