Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 如果一个单词不是';列表中的t应用程序脚本_Macos_Applescript_Osx Mavericks - Fatal编程技术网

Macos 如果一个单词不是';列表中的t应用程序脚本

Macos 如果一个单词不是';列表中的t应用程序脚本,macos,applescript,osx-mavericks,Macos,Applescript,Osx Mavericks,我正在写一个脚本,可以为我打开和关闭应用程序。基本上,我输入一个应用程序名,然后它打开应用程序。唯一的问题是,如果找不到应用程序,它会抛出一个错误并退出。我想让脚本只显示一个对话框,上面写着“找不到应用程序” 以下是我目前掌握的情况: if userInput contains "Activate " then set {TID, text item delimiters} to {text item delimiters, {"Activate "}} if length of userInp

我正在写一个脚本,可以为我打开和关闭应用程序。基本上,我输入一个应用程序名,然后它打开应用程序。唯一的问题是,如果找不到应用程序,它会抛出一个错误并退出。我想让脚本只显示一个对话框,上面写着“找不到应用程序”

以下是我目前掌握的情况:

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
顺便说一句,这只是我脚本的一个片段,这就是为什么这里有一些未定义的变量

我试过:

set appList to do shell script "cd /Applications; ls"
if openApp is not in appList then display dialog "App not found"
嗯,Applescript语法有时很烦人


谢谢。

有一个
存在的应用程序
,但这也会弹出一个对话框,询问“xyz在哪里?”

因此,你能做的最好的事情似乎是:

tell application "Finder" to set appExists to (exists file myApp of folder "Applications" of startup disk)

if not appExists then
    display alert "App not found"
end if
您的代码是:

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

tell application "Finder" to set appExists to (exists file (openApp & ".app") of folder "Applications" of startup disk)
if not appExists then
    display alert "App not found"
else
    if userInput contains "Activate " then tell application (openApp as string) to activate
end if
或者,如果用户按“取消”,则尝试捕获错误:

try
    if userInput contains "Activate " then tell application (openApp as string) to activate
on error
    display alert "App not found"
end try

但是你没有看到一个弹出窗口,问“xyz在哪里?”我有,但是如果我按“取消”,我会收到一条奇怪的消息谢谢,最后的建议对我来说效果最好。