Is there a 'unmount device' macro?

thank you for the clear and detailed instructions which I followed.

Hey Ronald

This AppleScript will provide a complete report of all installed OSAXEN.

Osax Report.scpt.zip (9.3 KB)

The 24U Appearance OSAX was a great scripting addition, but it has not been well supported in the last few years. (I don't like the way v4.x phones-home either.)

Default Folder 5 no longer relies on the Default Folder X Addition.osax.

The SIMBL.osax is not something you should have on your system, unless you know what requires it. It allows code-injection into apps, and theoretically is a serious security threat. I reluctantly stopped using utilities that required it several years ago for that reason and because it made my system a little less stable.

-Chris

2 Likes

Thank you. I deleted it, and thanks for the apple script

Thank you very much for the script. This is the result. What should I do now? I could delete textexpander which would be a pain because I have a library of snippets. That being said, I trust your advice

INSTALLED OSAX REPORT 2016/10/21 14:07


System Domain Osaxen

/System/Library/ScriptingAdditions/

Digital Hub Scripting.osax
StandardAdditions.osax


Local Domain Osaxen

/Library/ScriptingAdditions/

Adobe Unit Types.osax
Default Folder X Addition.osax
SIMBL.osax


User Domain Osaxen

~/Library/ScriptingAdditions/

TextExpander Addition.osax


/System/Library/ScriptingAdditions/ → Leave this folder as it is. These Additions are installed by macOS
Digital Hub Scripting.osax
StandardAdditions.osax

/Library/ScriptingAdditions/
Adobe Unit Types.osax → Installed by Adobe products. Check the version of the .osax (Finder Info), it should be 2.1.0. If it’s older then update it.
Default Folder X Addition.osax → See Chris’ (@ccstone) post above.
SIMBL.osax → Ditto.

~/Library/ScriptingAdditions/
TextExpander Addition.osax → Keep it if you’re using the Textexpander app.
‌

I could delete textexpander which would be a pain because I have a library of snippets.

I think nobody has said you should delete Textexpander.

1 Like

thank you

your help was invaluable. thanks so much for the applie script.

Thanks Tom! That is so awesome!!

Thanks for the feedback. Me too, I’m happy with the script :wink:

For a maximum of convenience you can map the trigger to the Media Eject key of your keyboard (⏏) as shown in one of the posts above. (I have not included that trigger in the downloadable macro because that key is probably device-specific.)

But: If you are going to map it to the ⏏ key, then I recommend to not do it as I have shown it in the post above: Instead of selecting “ignoring modifiers” I recommend to select “with these modifiers” with no modifier key selected. Like this:

The reason is, with that trigger you are still able to use the other, system functions of the ⏏ key. (The system functions of the ⏏ key are described here.)

Got it and thanks again! I had mapped the trigger to the Media Eject key like you mentioned in the post and it’s working great. I like that better than the hot key I had first set it up with. But now I’ll go back and change it to the way you suggest here.

After reading this thread and thinking about my situation I did a little study on Apple Script; wow it’s confusing! I was going to try to add to the script to unmount network drives/mounts but I couldn’t figure out how to do it. I found a way to list the disks that are not ‘local volumes” but then I couldn’t figure out how to do anything with them like list the contents of the disk or eject them. It may not be “ejectable” b/c it doesn’t show up in the list of disks with ejectable set to true but in Finder it has the little eject icon beside it and that’s how I disconnect from it normally (unless I forget and just unplug from the network). And that’s why I was hoping it would be ejected also just so I don’t mess up the network drive.

Not a big deal though and I may work on it some more when I have time; it was kind of a fun project. Now if you happen to know right off the top of your head how to eject a network mount using Apple Script then of course I would take your advice ha! But please don’t take this as a request for you to try to figure it out! I feel like you’ve already bent over backward to answer the questions on this thread.

Thank you very much for your help here!

Scott Murff
Bill Murff Turf Farm, Inc.
281-328-2812
www.murffturf.comhttp://www.murffturf.com

If you found it at all interesting, I encourage you to look into it. There are many great resources online and many great tutors here. I've been learning AppleScript (slowly) for the past few weeks and am really enjoying it.

1 Like

Thanks Christian! It was very interesting and I can see how it would make me more productive if I knew how to really use it; especially combining it with KM!

Remove or comment out the “whose ejectable is true” in line 2 of the script. So that it reads:

tell application "Finder" to set diskList to name of every disk --whose ejectable is true

Network-mounted folders should now also appear in the list and you should be able to unmount them with the script. (I only tried it with an AFP share.)

Note: The list will now be polluted with not-unmountable disks like for example your startup disk. However, this should only be a cosmetic problem, since nothing should happen when you try to unmount the startup disk.

When I find the time I’ll try to figure out how to exclude them from the list.

###Edit:

OK, try it with this as line 2 in the script:

tell application "Finder" to set diskList to name of every disk whose URL starts with "file:///Volumes/"

This should exclude things like the startup disk from the list.

1 Like

Thanks again Tom! I’ll give it a shot.

Please check again. I corrected a pasting error in the 2nd snippet (wrong variable name). Sorry, just seen it now.

Yes I changed that before. I wondered about it and got an error when Trying it so just changed it to diskList and it worked! The error said inVolume wasn’t defined and I figured it was just a typo or something.

Thanks for your help and expertise!

Scott

Thanks @Tom for providing these very good script.
Since I am not (yet) the best with AppleScript, would I be interested to know if such a "List Disks - Script" can also be used to activate selected discs?

Via Disk Utility:

Terminal:

diskutil mountDisk "Archive I"

where Archive I is the name of the disk.

(You can get the name of the disks with diskutil list.)

Or embedded in an AppleScript:

do shell script "diskutil mountDisk \"Archive I\""

OK, here is a simplistic macro to mount disks (derived from my “List and Eject Disks” macro):

Mount Disks [simple version].kmmacros (4.5 KB)

“Simplistic” because you have to manually set your list of disks in the AppleScript before the first run.

tell application "Keyboard Maestro Engine" to set theDisk to getvariable "previousDisk"
# Set your available disks here
set diskList to {"Archive I", "3TB-WD-B"}
if diskList does not contain theDisk then set theDisk to item 1 of diskList
tell application (path to frontmost application as text) to set theDisk to choose from list diskList with title "Mount Disk" with prompt "Select disk(s) to mount:" default items theDisk with multiple selections allowed
if theDisk is not false then
  repeat with i in theDisk
    do shell script "diskutil mount" & space & quoted form of i
  end repeat
  tell application "Keyboard Maestro Engine" to setvariable "previousDisk" to item 1 of theDisk
end if

‌

Edit/addition:

Here is an extended version of the “Mount Disc” macro from above:

It compares your disk list with the list of already mounted disks. Then it presents only the mountable disks (= disks that are not already mounted) in the list dialog.

Nevertheless, I leave the “simple” version of the script posted, because it cannot be excluded that a disk that is considered mounted is in reality not (properly) mounted, in certain cases. So, if you find that there are disks missing in the list dialog, then use the simple version from above, which just displays all disks, not regarding their presumed mount status.

List and Mount Unmounted Disks.kmmacros (5.6 KB)

tell application "Keyboard Maestro Engine" to set theDisk to getvariable "previousDisk"

# Set your available disks here
set diskList to {"Archive I", "3TB-WD-B"}

# Compare with the list of already mounted disks
set mountedDisks to {}
set mountableDisks to {}
try
  tell application "Finder" to set mountedDisks to name of every disk whose URL starts with "file:///Volumes/"
  # Alternate way (but usually the first way works better):
  # tell application "Finder" to set mountedDisks to name of every disk whose ejectable is true
end try
repeat with i in diskList
  if i is not in mountedDisks then set end of mountableDisks to i
end repeat

if (count of mountableDisks) < 1 then
  display alert "No mountable disks found."
  error number -128
end if

if mountableDisks does not contain theDisk then set theDisk to item 1 of mountableDisks
tell application (path to frontmost application as text) to set theDisk to choose from list mountableDisks with title "Mount Disk" with prompt "Select disk(s) to mount:" default items theDisk with multiple selections allowed
if theDisk is not false then
  repeat with i in theDisk
    do shell script "diskutil mount" & space & quoted form of i
  end repeat
  tell application "Keyboard Maestro Engine" to setvariable "previousDisk" to item 1 of theDisk
end if

While writing the “Mount” script above I found some minor issues in the original script. So, here an

Update for the “List and Eject Disks” macro (see original post)

Changes – ver 2.2:

  • ‘previousDisk’ now saves the first disk (so something gets saved if the list contains >1 entries).
  • Proper handling if no ejectable disk is found.

List and Eject Disks [ver 2.2].kmmacros (3.8 KB)

tell application "Keyboard Maestro Engine" to set diskToEject to getvariable "previousDisk"
try
  tell application "Finder" to set diskList to name of every disk whose URL starts with "file:///Volumes/"
  # Alternate way (but usually the first way works better):
  # tell application "Finder" to set diskList to name of every disk whose ejectable is true
on error
  display alert "No ejectable disks found."
  error number -128
end try
if diskList does not contain diskToEject then set diskToEject to item 1 of diskList
tell application (path to frontmost application as text) to set diskToEject to choose from list diskList with title "Eject Disk" with prompt "Select disk(s) to eject:" default items diskToEject with multiple selections allowed
if diskToEject is not false then
  tell application "Finder" to eject diskToEject
  tell application "Keyboard Maestro Engine" to setvariable "previousDisk" to item 1 of diskToEject
end if