Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

thebart

macrumors 6502a
Original poster
Feb 19, 2023
515
518
I wrote an AppleScript to mount an SMB share if it is not already mounted. It also tries 10x on failure with a delay in between. This part is working.

What I really want to do is to run this automatically when the share is disconnected for whatever reason. I thought I could use folder action for this.

My steps:
  • open automator, create folder action
  • for "Folder action receives files and folder added to .." select /Volumes as the folder to watch.
  • select "Run applescript" from list of actions
  • paste in my script, which is now wrapped with
Code:
on removing folder items from this_folder after losing these_items
...
end removing folder items from

Then I save it. It saves as a .workflow by default. It does not let me choose a folder so I don't know where it is saved and I can't find it in the finder.

In theory, this should watch /Volumes and when something is removed it should check and mount the smb share if necessary. But nothing seems to happen.

So I changed the watch folder to ~/Downloads and added in some display dialog ... debug print to see if the script is getting triggered at all when I add or remove files from ~/Downloads. But nothing happens. The script is not being triggered.

Anyone knows what I'm doing wrong?

thanks
 

KALLT

macrumors 603
Sep 23, 2008
5,380
3,415
Folder actions are stored in your user library under ~/Library/Workflows/Applications/Folder Actions.

You can use the Folder Actions Setup application (look for it with Spotlight) to enable/disable your workflows and set the folder for which they should be triggered.
 

thebart

macrumors 6502a
Original poster
Feb 19, 2023
515
518
Ah, thanks.

It turns out it only triggers when items are added, not removed, which is not helpful in this case. I tried attaching to ~/Downloads with same result. Not sure if I'm doing something wrong or this is a bug with Sonoma or with my system.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.