Help - Search - Members - Calendar
Full Version: mount/unmount ipod script
InsanelyMac Forum > Apple World > Mac Programming and Development > AppleScript and Automator
Suzuka
Im working on a script that will mount or unmount a drive depending on if its mounted or not, so far I have this,

CODE
tell application "Finder"

if exists folder "/Volumes/Advent iPod" = false then
diskutil mount "/dev/disk2s3"

else if exists folder "/Volumes/Advent iPod" = true then
diskutil unmount "/Volumes/Advent iPod"
end if
end tell


however, when I run it, I get a Syntax error
QUOTE
Expected “then”, etc. but found “.


it then highlights the " in the line
CODE
if exists folder "/Volumes/Advent iPod" = false then


what am I doing wrong, I'm not very experienced in applescripts
PascalW
QUOTE(Suzuka @ Apr 21 2007, 04:26 AM) *
Im working on a script that will mount or unmount a drive depending on if its mounted or not, so far I have this,

CODE
tell application "Finder"

if exists folder "/Volumes/Advent iPod" = false then
diskutil mount "/dev/disk2s3"

else if exists folder "/Volumes/Advent iPod" = true then
diskutil unmount "/Volumes/Advent iPod"
end if
end tell


however, when I run it, I get a Syntax error
it then highlights the " in the line
CODE
if exists folder "/Volumes/Advent iPod" = false then


what am I doing wrong, I'm not very experienced in applescripts


You could try something like:

CODE
set x to "0"
try
    do shell script "ls '/Volumes/Advent iPod'"
on error
    set x to "1"
end try
if x = "0" then
    do shell script "disktool -u disk2s3"
else if x = "1" then
    do shell script "disktool -m disk2s3"
end if


Just save it as an applescript app and run it. If the ipod is mounted it will unmount it and quit the app, if it is not mounted it will mount it and then quit.
A Nonny Moose
you shouldn't need the "" in the folder path unless you're trying to treat more than one word as a collective unit.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.