2017-08-10 67 views
0

我試圖從文件執行代碼,但未能路徑正確的 引用並獲取以下錯誤。引用文件錯誤

Safari got an error: 
Can’t get file "Main:Users:Adrian:Documents:Portfolio:automation:explorer:logic.js" of window 1. 


我曾嘗試做這樣:

tell application "Safari" 
    tell window 1 
     set current tab to make new tab with properties {URL:"...some"} 
     delay 5 
     do JavaScript file "Main:Users:Adrian:Documents:logic.js" in current tab 
    end tell 
end tell 


和...

tell application "Safari" 
    tell window 1 
     set current tab to make new tab with properties {URL:"...some"} 
     delay 5 
     do JavaScript (file "Main/Users/Adrian/Documents/explorer.js") in current tab 
    end tell 
end tell 

我指定的路徑是我採取的方法從應對文件信息的路徑(釐米d + I)

/Users/Adrian/Documents/logic.js 

主要是硬盤驅動器名稱

回答

1

do JavaScript參數必須是text,所以你可能必須先讀取文件。 Btw:POSIX路徑始終以代表啓動卷的斜槓啓動,與以磁盤名稱開頭的以冒號分隔的HFS路徑不同。

set jsText to read "/Users/Adrian/Documents/explorer.js" as «class utf8» 
tell application "Safari" 
    tell window 1 
     set current tab to make new tab with properties {URL:"...some"} 
     delay 5 
     do JavaScript jsText in current tab 
    end tell 
end tell 
+0

謝謝你很多,爲了一個很好的解釋。它確實幫了大忙! :) – volna