Good Afternoon everyone (newbie trying first script attempt)
I’ve been looking through the forums for most of this morning, attempting to find a way to ensure my AppleScript waits for my external compact flash Card is mounted on the desktop, before moving on to the next tell block in my script.
What I’ve tried so far compiles OK, but doesn’t return my “Mounted Successfully” dialog - indicating that my attempt at the script isn’t working.
Here’s the script I’ve been trying to put together.
set mountedDisk1 to list disks
set thevolume1 to "CFCARD"
activate
--use activate to bring dialog to front
display dialog "Please insert Compact Flash Card"
delay 6
tell application "Finder"
if (not (exists (disk "CFCARD"))) then
repeat until mountedDisk1 contains thevolume1
if mountedDisk1 contains thevolume1 then
end if
end repeat
end timeout
end if
end tell
display dialog "CFCARD Mounted Successfully"
I’m probably way off the mark with this, but if someone could offer comments, & maybe explain the way AS checks for this situation, I may have better luck with my next script attempt.
When you started your script, you got every disk into a list. You later told Finder to go through the list until it changes to include your CF card. However, you never updated your list. Even if you inserted your card, the list you got at the beginning wasn’t updated, so the list you are lopping through will never include your CF Card. All you have to do is update your list every time you loop through it.
Try this:
set mountedDisk1 to list disks
set thevolume1 to "CFCARD"
set wasmounted to false
activate
--use activate to bring dialog to front
if mountedDisk1 contains thevolume1 then
display dialog "CFCARD Mounted Successfully"
set wasmounted to true
else
display dialog "Please insert Compact Flash Card"
end if
if wasmounted is false then
delay 6
tell application "Finder"
if (not (exists (disk "CFCARD"))) then
repeat until mountedDisk1 contains thevolume1
set mountedDisk1 to list disks
if mountedDisk1 contains thevolume1 then
--successful
end if
end repeat
end timeout
end if
end tell
display dialog "CFCARD Mounted Successfully"
end if
I also set it to check if the CF Card was mounted in the first place.
I’m sorry but I may not be able to answer replies for the time being.
Thanks for the info, I’m working through your comments with my AS Book in an effort to properly understand how this is put together, and have run the script several times to prove it works . . . . and it does, very well in fact!
. . . . however, if I try a similar script for checking if a blank DVD has been inserted (& has mounted itself on the desktop), it doesn’t seem to work!
I’ve inserted check dialogs in relevant places hoping to see where the problem lies, and even without the blank disk inserted, I’m getting the “OK 2” dialogue, so something’s not correct in the top section of my script. It shouldn’t get to this stage if the "Untitled DVD’ hasn’t appeared on the desktop!
I’ve looked over this and changed it many times, but I still can’t understand why this isn’t working correctly.
Just wondering if the problem is in the - set mountedDisk2 to list disks - section??
What exactly does this script do? Can’t find it in my book!
set mountedDisk2 to list disks
set thevolume2 to "Untitled DVD"
set wasmounted2 to false
activate
display dialog "Please Insert Blank DVD"
--use activate to bring dialog to front
delay 1
if mountedDisk2 contains thevolume2 then
set wasmounted2 to true
end if
display dialog "OK 2"
if wasmounted2 is false then
delay 3
tell application "Finder"
if (not (exists (disk "Untitled DVD"))) then
repeat until mountedDisk2 contains thevolume2
display dialog "OK 3"
set mountedDisk2 to list disks
if mountedDisk2 contains thevolume2 then
--successful
end if
end repeat
end if
end tell
display dialog "Blank DVD Inserted and ready to Burn"
end if
The problem is very simple: A blank disc cannot be mounted, because there is no file system on it.
Therefore it will never appear in /Volumes.
Check the disc info parameter of /usr/bin/drutil
display dialog "Please Insert Blank DVD"
repeat until (do shell script "drutil discinfo") does not contain "Please insert"
delay 1
end repeat
display dialog "Blank DVD Inserted and ready to Burn"
Thanks very much for the information, yes I can understand that the DVD has no file system on it, therefore it can’t be “mounted”.
Makes sense.
The script works well with the one I have above, the only other addition I made was:
activate
display dialog "Blank DVD Inserted and ready to Burn
For some reason, I’ve had to put “activate” above dialog script elsewhere too.
I’ve noticed that in other posts on this forum, this is not the case.
Am I correct in assuming that the word “activate” forces the dialog to appear on top of everything else?
I’ve been using the shell script you gave me a few days ago, to check when a blank DVD has been inserted into my iMac.
display dialog "Please Insert Blank DVD"
repeat until (do shell script "drutil discinfo") does not contain "Please insert"
delay 1
end repeat
display dialog "Blank DVD Inserted and ready to Burn"
But for some reason, it’s stopped working this evening.
I haven’t added any further scripts to my “Master Script”, so it really should work fine.
Do you have any idea’s why this might have happened?
I’ve found that if I put a delay 3 between the end repeat and the final display dialog, it seems to work over and over again!
activate
display dialog "Please Insert Blank DVD"
repeat until (do shell script "drutil discinfo") does not contain "Please insert"
delay 1
end repeat
delay 3
activate
display dialog "Blank DVD Inserted and ready to Burn"
Is this something to do with the repeat script loop?
Would it help to put a timeout script in here somewhere, with a dialog telling me “Taking too long to insert DVD” (or something like that)?