2014-09-29 76 views
-1

我已經爲不同的命令提出了類似這樣的問題,但這對我來說稍微複雜一些。下面是代碼:爲什麼這個命令大部分時間不工作?

set appLocation to ((path to me) as string) 
set theFile to appLocation & "Contents:iPanic.app" 
tell application "System Events" to open file theFile 

有兩種結果發生後此嘗試運行,無論是「可變appLocation沒有定義」或「文件中的一些對象未找到」。我已經嘗試過將文本作爲文本的路徑,但仍會出現此錯誤。奇怪的問題是這個命令有時會起作用,並且大部分時間對其他文件也是如此。

set appLocation to ((path to me) as string) 
set theFile to appLocation & "Contents:open" 
tell application "System Events" to open file theFile 

兩者都非常相似,但有非常不同的結果。如果有人能夠理解爲什麼會發生這種情況,我很想知道。 Thankyou

EDIT-是由於我添加.app文件導致錯誤「File some object was not found」。由於它是一個應用程序,但沒有顯示擴展名。

+0

製作一個新的Applescript並輸入:'get path to me'並查看結果。如果這不是你每次想要獲得的東西,那麼當你運行'路徑給我'時,你需要改變你想要替換的位置。 – 2014-09-29 21:59:16

+0

是的,路徑似乎是正確的,我只是沒有爲什麼它有時會起作用,並且在其他時間不起作用。我想知道是否會將別名放在((我的路徑)前面,因爲字符串會起作用 – 2014-09-30 00:53:55

+0

沒關係,它不起作用 – 2014-09-30 00:56:32

回答

0

有幾個問題需要解決。首先關閉應用程序,我試圖用必須先激活的文件來打開文件。所以它只會是:

tell application "System Events" 
activate 

set appLocation to ((path to me) as string) 
set theFile to appLocation & "Contents:iPanic.app" 
tell application "System Events" to open file theFile 

end tell 

也取決於文件類型:.mp3,.app等我認爲它也很重要什麼應用程序打開它。如果打開.mp3,Finder將與.mp4及其他媒體文件一起使用效果最佳。 System Events最適合.app。