查找文件在Finder中的问题中选择 [英] Finding a file selecting it in finder issue
问题描述
我有这个脚本来查找文件并选择它。
I am having this script to find a file and select it
set filePath to ("filePath.ext" as POSIX file)
tell application "Finder"
if (exists filePath) then
select filePath
activate
else
display alert "File " & filePath & " does not exist"
end if
end tell
这是在Mac OS X 10.6.x的(LION)完美的工作很好,但,当我尝试运行在Mac OS X 10.5(雪豹纹)这个脚本是选择文件,但服用太多的时间。任何建议我怎么能在Mac的两个版本这个code做工精细。
在此先感谢:)
it is working perfect well on Mac os x 10.6.x (LION) but when I try to run this script on Mac os x 10.5.x (snow-leopard) it is selecting file but taking too much time. Any suggestion how can I make this code work fine on both versions of Mac. Thanks in advance :)
编辑:
我从网络驱动器中选择文件及旅馆系统是有一个Windows操作系统。所有系统都位于同一网络中的
I am selecting file from a network drive and hostel system is having a Windows Os. All systems are located in the same network.
推荐答案
的显示
命令可能对你的帮助。它只是位于取景器的文件,如果需要打开一个新的窗口,然后选择文件的所有只用一个code线:
The reveal
command may be of assistance to you. It simply locates a file in the finder, opens a new window if necessary, and then selects the file—all that using just one line of code:
tell application "Finder" to reveal path:to:some:file
该文件必须实际存在这个工作的,当然。你知道,当它在别名形式psented $ P $存在一个特定的文件/目录(即的Macintosh HD:用户:billybob:桌面:howToHack.pdf
)。试图强迫一个不存在的文件到一个别名将会导致错误。如果你是100%肯定该文件存在,并确切地知道它在哪里,恭喜你!你少了一个事情操心。如果你的确定性水平低于100%什么,使用的try-catch
块。它们保存在多个场合我的生活。这样,如果你通过互联网分发应用程序像我这样做,你的客户是不是无法破解的错误消息psented $ P $。
The file must actually exist for this to work, of course. You know a particular file/directory exists when it is presented in alias form (I.e. Macintosh HD:Users:billybob:Desktop:howToHack.pdf
). Attempting to coerce a nonexistent file into an alias will result in an error. If you are 100% certain that the file exists and know exactly where it is, congratulations! You have one less thing to worry about. If your certainty level is anything less than 100%, use a try-catch
block. They have saved my life on multiple occasions. That way, if you distribute your applications via the Internet like I do, your clients are not presented with undecipherable error messages.
这方面的一个例子如下所示:
An example of this is demonstrated below:
set theFile to "/Users/billybob/Desktop/folder/subfolder/subfolder2/subfolder3/fineByMe.mp3"
try
set theFile to (theFile) as alias
tell application "Finder" to reveal theFile
on error
display alert "The file " & quoted form of theFile & "does not exist."
-- The variable 'theFile' couldn't be coerced into an alias.
-- Therefore, 'theFile' still has a string value and it can be used in dialogs/alerts among other things.
end try
这是更有效或更耗时比你写的是什么?我不是特别肯定,是诚实的。不过,我写了包括了许多脚本显示
在Mac OS X 10.5.8(Leopard)上的Mac OS X 10.6.8(雪豹)和命令的Mac OS X 10.7.3(狮),结果已被满足。
Is this more efficient or less time consuming than what you've written? I'm not particularly sure, to be honest. However, I have written many scripts that have included the reveal
command on Mac OS X 10.5.8 (Leopard), Mac OS X 10.6.8 (Snow-Leopard), and Mac OS X 10.7.3 (Lion), and the results have been satisfying.
这篇关于查找文件在Finder中的问题中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!