One of my scripts must mount a disk image storing datas which aren’t supposed to be inline all the time.
At this time the useful code doing the job is :
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions
property |⌘| : a reference to current application
set p2d to path to desktop as text
set diskYK to "resources YK" -- the name of the mounted disk image
set diskImageURL to (p2d & diskYK & ".sparseimage") as «class furl»
set diskImageURL to (|⌘|'s NSArray's arrayWithObject:diskImageURL)'s firstObject()
set diskURL to (|⌘|'s NSArray's arrayWithObject:(diskYK as «class furl»))'s firstObject()
set avail to (diskURL's checkResourceIsReachableAndReturnError:(missing value)) as boolean
if not avail then do shell script "hdiutil attach " & quoted form of (diskImageURL's |path|() as text)
Is it a way to achieve this task without using do Shell Script ?
In the help of Xcode I found instance methods named “attach” belonging to Kernel but I really don’t know if we may trigger them with ASObjC.
As the help just states : “No overview available”, it doesn’t really help me.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 10 février 2020 18:06:43
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions
property |⌘| : a reference to current application
set p2d to path to desktop as text
set diskYK to "resources YK" -- the name of the mounted disk image
set p2alias to p2d & diskYK -- alias pointing upon the sparseimage
set aliasURL to (|⌘|'s NSArray's arrayWithObject:(p2alias as «class furl»))'s firstObject()
set forYK to (aliasURL's checkResourceIsReachableAndReturnError:(missing value)) as boolean
if forYK then set diskURL to (|⌘|'s |NSURL|'s URLByResolvingAliasFileAtURL:aliasURL options:0 |error|:(missing value))
I tried to do that with a symlink but got nothing.
I may also unmount the disk with:
use AppleScript version "2.5"
use framework "Foundation"
use framework "AppKit" -- for Workspace
use scripting additions
property |⌘| : a reference to current application
set diskYK to "resources YK" -- the name of the mounted disk image
set diskURL to (|⌘|'s NSArray's arrayWithObject:(diskYK as «class furl»))'s firstObject()
if (diskURL's checkResourceIsReachableAndReturnError:(missing value)) as boolean then
set theNSWorkspace to |⌘|'s NSWorkspace's sharedWorkspace()
theNSWorkspace's unmountAndEjectDeviceAtURL:diskURL |error|:(missing value)
end if
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 11 février 2020 11:39:29