AppleScript的,以检查是否存在的文件 [英] Applescript to check if files exist
问题描述
我要检查是否有任何特定的文件(字典)中的/资源库/词典/存在。这里是我的AppleScript code线:
I want to check if any of particular files (dictionaries) exist in "/Library/Dictionaries/". Here is my Applescript code lines:
tell application "Finder"
try
set theFolder to ("/Library/Dictionaries/")
set fileNames to {"dict1.dictionary", "dict2.dictionary", "dict3.dictionary", "dict_n.dictionary"}
on error
set fileNames to false
end try
if fileNames is not false then
try
display dialog "You have already got the dictionary."
end try
end if
end tell
古怪,消息您已经得到了词典。
总是尽管没有公开的文件显示存在。
Weirdly, the message You have already got the dictionary.
is always shown albeit no listed files exist.
我的目的是检查是否有任何列出的文件出口的,如果一个或更多的人退出则消息是要显示。
My purpose is to check if any of the listed files exits, and if one or more of them exits then the message is to be displayed.
事实上,该脚本将通过的/ usr / bin中/ osascript
运行在Unix bash脚本,所以我会很感激,如果你可与苹果帮助脚本或Bash脚本。
In fact, this script will be run as a Unix bash script via /usr/bin/osascript
, so I will be very grateful if you can help with either Apple script or Bash script.
推荐答案
尝试
set theFolder to (path to library folder as text) & "Dictionaries:"
set fileNames to {"Apple Dictionary.dictionary", "dict2.dictionary", "dict3.dictionary", "dict_n.dictionary"}
set dict to {}
repeat with aFile in fileNames
tell application "Finder"
if exists file (theFolder & aFile as text) then set end of dict to aFile & return
end tell
end repeat
if dict ≠ {} then display dialog "You have the following dictionaries installed:" & return & dict
这篇关于AppleScript的,以检查是否存在的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!