0

I am a total Applescript newbie - mostly I work by copying examples.

I have created a simple droplet that uses the image mounter built into Toast to mount disk images that are dropped on the droplet without actually launching the full Toast program. The droplet works, but I would like the script to quit once the disk images are mounted. (As things stand now, the script application becomes unresponsive shortly after the images are mounted, but sometimes it doesn't quit when the images are dismounted.) I searched the forum and figured out I'm supposed to do a "redirect" using > /dev/null 2>&1 &, but I can't get the syntax right.

May I please have some help - Thanks!

on open image

set mount to "/Applications/'Toast 11 Titanium/Toast Titanium.app'/Contents/MacOS/ToastImageMounter"

repeat with path in image

    set mount to mount & space & quote & POSIX path of path & quote

end repeat

do shell script mount

end open

EDIT: I solved it, but I'm sure this isn't the most elegant solution, so I'd appreciate feedback.

on open image

set mount to "/Applications/'Toast 11 Titanium/Toast Titanium.app'/Contents/MacOS/ToastImageMounter"

set foo to space & "> /dev/null 2>&1 &"

repeat with path in image

    set mount to mount & space & quote & POSIX path of path & quote & foo

end repeat

do shell script mount

end open

hmom
  • 1
  • 2
  • Looks elegant to me, apart from using "mount" as a variable. If I were you I'd use something like "theMount". It's one of those words that is too likely to be a command in some dictionary/command set. For info on the redirect, see [http://stackoverflow.com/questions/10508843/what-is-dev-null-21] – CRGreen Sep 14 '14 at 20:00

1 Answers1

0

I'd change a couple things. First, why do you have single quotes in your path to the toast titanium mounter? It doesn't make sense because you want to quote the whole path, not just a small portion of it. Note that in applescript we have "quoted form of" to place the quotes properly around stuff so I used that in 2 places of your code. Second, the point CRGreen makes about variable names is valid so be careful just to avoid unnecessary issues. I'd change both mount and path. Finally, you want to add foo one time at the end of the command instead multiple times inside the repeat loop.

As such here's how I would write your code. Good luck.

set mountCMD to quoted form of "/Applications/Toast 11 Titanium/Toast Titanium.app/Contents/MacOS/ToastImageMounter"

set foo to space & "> /dev/null 2>&1 &"

repeat with thisPath in image
    set mountCMD to mountCMD & space & quoted form of POSIX path of thisPath
end repeat

do shell script mountCMD & foo
regulus6633
  • 18,848
  • 5
  • 41
  • 49