Tuesday, January 21, 2020

#1 2020-01-16 05:51:17 am

Registered: 2006-08-14
Posts: 72

Folder Action to launch an app's "on open" handler


I am trying to work out to write a folder action script that launches a separate AppleScript application that will process the files/folders dropped in the hot folder as if the item was dragged and dropped on the application icon itself.

In other words I'm trying to write a folder action that runs the app's "on open" handler and then processes the dropped files one by one.

P.S.   I also have an "on run" handler in the app which runs when the application when clicked on by the user (this handler is used to change setting etc).

I have the application done and it works fine when items are dropped on it.  What I can't work out is how to write the folder action script so that I can have a hot folder that does the same.

Hope this is clear.

Any help would be appreciated.



Last edited by timbaldwin (2020-01-16 05:52:25 am)




#2 2020-01-16 08:45:38 am

Yvan Koenig
Registered: 2006-09-14
Posts: 3877

Re: Folder Action to launch an app's "on open" handler

You may try something like :


on adding folder items to this_folder after receiving these_items
   set targetApp to ((path to desktop as text) & "droplet.app:") as «class furl»
   tell application "Finder"
       open these_items using targetApp
   end tell
end adding folder items to

I tested it with the droplet "droplet.app" whose code is :



on open sel # sel contient une liste d'alias des éléments
   # qu'on a déposés sur l'icône du script (la sélection)
   repeat with aFile in sel
       set itsName to name of (get info for aFile)
       display notification itsName sound name "Ping"
       delay 2
   end repeat
end open #


Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 16 janvier 2020  15:45:25



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)