Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Pass arguments and run GUI AppleScripts via cron' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Pass arguments and run GUI AppleScripts via cron
Authored by: lar3ry on Sep 19, '05 01:50:08PM
First, notice that the original poster used "$@" (in quotes). That is subtly different than the simplistic $* that you suggest. The difference is that shell will correctly process complex arguments if necessary (eg, if one or more arguments passed has spaces in it as in the original poster's test example).

Second, the original script outputs a single line for each (quoted) argument.

Third, the applescript extracts the arguments by using set passedArgs to paragraphs of argArray. This means that each line in the file is a single item in passedArgs.

The original solution is therefore much more flexible and rubust and it's also less error prone than your "optimized" solution, which will fail at unexpected times.

Shell programming can be simple, but there are many subtle complexities, which aren't really for the faint of heart.

[ Reply to This | # ]

Pass arguments and run GUI AppleScripts via cron
Authored by: leenoble_uk on Sep 19, '05 02:47:20PM

I'm no Shell guru myself. It took quite a lot of repeated Google searches and misplacing of quotes to reach that end. I was trying to use backslash-n to generate new lines. I used odd sequences of characters as argument delimiters. Apparently you can contract it further by removing the curly braces and writing:


ARGFILE="${thePath}/folder-action-arguments.txt"

for i in "$@"; do
echo "$i"
done > "$ARGFILE"

Also since the 4 second sleep is only necessary if the file existed before then


if [ -f "$ARGFILE" ]; then
    rm "$ARGFILE"
    sleep 4
fi

will remove the delay. Credit to Mark J Reed on the Applescript Users mailing list for that.

By the way, the Applescript needs to be amended to move the file.
It should read:


move file (actionFile as string) to the trash

---
So, I said ... well, I can't actually remember exactly what I said. But it was one of the most enormously cruel and frighteningly witty put downs ever.

[ Reply to This | # ]