Quick Action ‘shortcut’ to clear metadata from a file in Finder

When you use AirDrop to move an image from your iOS device to your Mac macOS adds some metadata that made me uncomfortable. In particular, the com.apple.metadata:kMDItemWhereFroms metadata is a binary property list which includes the name of the device it came from. The default name is often your name, as in, “Dad’s iPhone 12 Pro”.

Lots of ways you might share that image which don’t copy that data, but copying the file to another Mac through an external hard drive or file sharing, at minimum, seems to transfer this metadata across.  Sending as an email attachment, or as a Messages message attachment doesn’t seem to transfer this metadata, on the other hand.  It would be nice to have a preference to prevent adding this to the file metadata (FB10992657).

Since I’m not 100% clear when this metadata is getting transferred and when it isn’t, I wrote a small macOS Shortcut to strip it.  First Shortcut I’ve put together and the lack of logging for shell commands or of any kind makes Shortcuts significantly less usable than Automator, for example (where I had to go to figure out what was going wrong).  Also the initial text for an Run Script node in a Quick Action are not as helpful as the Automator environment (FB10993044).

Anyway, here’s the result:

ClearMetadata

I’d attach the actual shortcut file but Apple chooses to make them tightly linked to the creator and doesn’t allow sharing the source code for the shortcut without attaching my AppleID certificate to the file (WTH?!) (FB10993444).

Advertisement

AppleScript to search the contents of Safari Windows & Tabs

I have too many windows open in Safari (416 tabs in 133 windows currently – yah, I wrote an AppleScript to count those 🙂 ).

Got tired of not being able to find something I knew I had open so I wrote an AppleScript to search the text content of all Safari tabs in all Safari windows that aren’t minimized (even across Spaces).  Does not currently search tabs in windows that are minimized to the dock.

I’ve now found this useful enough that I thought I’d share it.  Disclaimer: I’m not an AppleScript programmer and don’t really like AppleScript (probably because I don’t know the language and tricks!).  There are likely things that could be done better or smarter.  Contributions welcome.

That said, this seems to generally work and, thanks to me learning about using references, fast enough that I wasn’t sure it was actually working at first 🙂

Source is on GitHub here.

Instructions for installation are in the Read Me there.

AppleScript to eject mounted local volumes

AppleScript to eject mounted attached volumes/disks.

I have a MBP which I use with a Thunderbolt dock to connect to various USB and thunderbolt hard drives, SSDs, and optical drives. This script lets me eject and unmount anything physically connected before disconnecting my Thunderbolt dock.

Yah, sure, OWC makes a utility you can install that’ll do this, but it installs a kernel extension which I wasn’t keen on installing.

-- AppleScript I wrote to eject mounted USB disks before I disconnect my USB-C hub.
-- Notes: 
-- this will halt a time machine backup to a locally mounted 
--   drive when it tries to eject it.
--   will also halt a time machine backup to a network destination.
-- tested in macOS 11.6 (2021.11.19)
-- License:  MIT

tell application "System Events"
  set ds to get disks
  
  -- for debugging
  if false then
    log "list of disks: "
    repeat with d in ds
      log (get the URL of d)
      log (get the name of d)
    end repeat
  end if
  
  log ("Ejecting local ejectable volumes")
  repeat with d in ds
    -- before we try to do anything with this disk    
    -- try to access the disk and catch any errors 
    -- as a way to test if the disk is still present.
    -- set a flag that we can test below.
    set diskAvailable to true
    try
      set trashme to (get the name of d)
    on error errormsg number errorno
      if errorno is -1728 then set diskAvailable to false
    end try
    
    -- Notes:
    -- ejectable excludes sparse volume mounts for time 
    -- machine, but also means other ejectables aren't unmounted…
    -- ...decided to remove this in the if clause below and let it halt 
    -- time machine backups even for network volumes also
    -- since I'm generally calling this script when I'm disconnecting
    -- the laptop and heading out.
    --         d is not ejectable and ¬
    
    -- starts with "Data@" excludes time machine local snapshot
    --    mounts during backups
    -- starts with file:///Volumes excludes file:///System/Volumes/... 
    --  system volumes.
    -- local volume excludes network mounts
    
    
    if diskAvailable and ¬
      d is local volume and ¬
      the URL of d starts with "file:///Volumes/" and ¬
      the displayed name of d does not start with "Data@" then
      log ("........ ejecting:  " & (get the name of d))
      tell application "Finder" to eject (get the name of d)
    else if diskAvailable then
      log ("   Skipping: " & (the URL of d))
    else
      log ("  Skipping disk that is no longer available")
    end if
  end repeat
  log (" all ejectable local volumes ejected")
end tell

Posted as a gist here for easier copying and using.