1

I am trying to setup a watch folder so that when a file is added to a folder, I can run a shell script...for this purpose I made a simple test but cannot make it work...

Here is my applescript

on adding folder items to theWatchedFolder after receiving theDetectedItems
    activate
    display dialog "Transcode Successful"
    do shell script "/Users/wme/Desktop/script.sh" & theDetectedItems
end adding folder items to

and the script.sh

#!/bin/sh
f="$1"
do
    name=$(basename "$f")
    dir=$(dirname "$f")
    notify-send "$name"
done

While it does alert me "Transcode Successful" So I do know that the applescript is working...I dont get notified via the shellscript that the correct filename has transmitted...how do I do that?

1 Answer 1

1
on adding folder items to p after receiving input
    set l to {}
    repeat with f in input
        set end of l to quoted form of POSIX path of f
    end repeat
    set text item delimiters to " "
    do shell script "bash ~/Desktop/script.sh " & (l as text)
end adding folder items to

You can also use Automator to create folder actions that run shell scripts directly:

1
  • using l as a variable is very confusing because it looks like the number 1. I spent ages trying to work out how your script worked until I realised.
    – stib
    Jan 31, 2017 at 10:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .