2017-01-02 69 views
0

作爲較大項目的一部分,我希望獲取託管腳本的設備掛載點的路徑。
我在腳本編輯器中設計了以下代碼,但是,在ApplescriptObjC(Xcode)中實現它後,我發現錯誤開始發生。ApplescriptObjC到磁盤的路徑(主機驅動器)

# Get Mount Point of script USB host 
tell application "Finder" 
    try 
     set usbMountPoint to text 1 thru -2 of POSIX path of (disk of (path to me) as alias) 
     log usbMountPoint # Output: /Volumes/usb-drive-name 
    on error 
     set usbMountPoint to POSIX path of (disk of (path to me) as alias) # if file is on desktop, path: '/', can't have '[space]' hence no removing 
     log usbMountPoint # Output: /Volumes/usb-drive-name 
    end try 
end tell 

不能使«類ocid»ID«數據optr00000000207F220080600000»到類型常量。 (錯誤-1700)

我在代碼中包含了關於記錄輸出應該如何顯示的註釋。 據我所知,在Xcode中有關path to me問題的類似問題已經被問到過,而set myPath to current application's NSBundle's mainBundle()'s bundlePath()給出了當前路徑,但是,我的問題是關於它的disk of部分。

任何幫助在Xcode獲得所需的輸出非常感謝。

回答

1

它需要很多的強制的,但AppleScriptObjC相當於Xcode是

set myPath to current application's NSBundle's mainBundle()'s bundlePath() as text 
tell application "Finder" to set mountPoint to POSIX path of (disk of item (myPath as POSIX file as text) as alias) 
log mountPoint 

啓動卷被/所有其他卷由/Volumes/<volumeName>

代表
相關問題