ApplescriptObjC path to disk (host drive)

65 views Asked by At

As part of a larger project I would like to get the path of the Mount Point of the device which hosts my script.
I have designed the following code in Script Editor, however, upon implementing it in ApplescriptObjC (Xcode), I noticed that error started occuring.

# 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

Can’t make «class ocid» id «data optr00000000207F220080600000» into type constant. (error -1700)

I have included comments in the code as to how the logged output should look. I understand that similar questions regarding the path to me problem in Xcode have been asked before, and that set myPath to current application's NSBundle's mainBundle()'s bundlePath() gives the current path, however, my question is concerning the disk of part of it.

Any help in getting the desired output in Xcode is greatly appreciated.

1

There are 1 answers

0
vadian On BEST ANSWER

It requires a lot of coercions but the AppleScriptObjC equivalent in Xcode is

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

The startup volume is represented by / all other volumes by /Volumes/<volumeName>