0

Ok so if I want to open a random file from a folder on my Mac, I can use the following script succesfully:

tell application "Finder"

    open some file of (folder ("⁨⁨Users:chris:Desktop:photoAlbum") of startup disk)
end tell

However, I'm not sure what syntax to use when I want to open a random file from a volume/disk image I have mounted. The volume is located at /Users/chris/Downloads/photoAlbum.dmg but the following is not successful:

tell application "Finder"

    open some file of (folder ("⁨⁨Users:chris:Downloads:photoAlbum.dmg") of startup disk)
end tell

What script should I be using instead to do the latter?

  • 1
    The volume is not mounted at /users it is mounted at /Volumes/[volume name]/the/rest/of/your/path but only once it is actually mounted. Before that you cannot see inside it. – Tetsujin Dec 19 '19 at 18:51
0

Provided the disk in question is not already mounted, then:

tell application id "com.apple.Finder"
    set downloads to the path to the downloads folder
    set _files to a reference to files in downloads
    set _disks to the name of every disk
    set _dmgs to the name of the _files whose name extension = "dmg"
    set _selection to choose from list of _dmgs with multiple selections allowed

    open (the _files whose name is in the _selection)
    set _volumes to a reference to (the disks whose name is not in _disks)

    repeat until (_volumes exists)
        delay 1
    end repeat

    open some file in some disk of (get _volumes)
end tell
| improve this answer | |
  • @user3439894 For scripts, I indent with using hard tabs that have a width of 8 spaces (StackExchange converts these to spaces, which is a bit annoying). I indent config files with 2 spaces; and serialised nested output with 4 spaces. ¯\_(ツ)_/¯ Admittedly, the hard tabs can be problematic in a shell, but I set my shells up to cater for it. – CJK Dec 21 '19 at 4:47
  • @user3439894 I just reduced it to 4 spaces, since it's the more conventional indentation. – CJK Dec 21 '19 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.