i am trying to write a script, which waits for a certain volume (usb stick) and does something when the right volume finally is present.
thing is, the volume is one of 20 possible volumes, and the script sould say “thank you” if ANY of the 20 is inserted.
i have it tried like this:
set disk_list to {"USBack01", "USBack02", "USBack03", "USBack04", "USBack05", "USBack06", "USBack07", "USBack08", "USBack09", "USBack10", "USBack11", "USBack12", "USBack13", "USBack14", "USBack15", "USBack16", "USBack17", "USBack18", "USBack19", "USBack20"}
tell application "Finder"
repeat until name of every disk contains items of disk_list
say "insert disk"
end repeat
say "thank you"
end tell
i did not found anything for solving, maybe because it’s soo easy???
the script must run on an vintage G4 PCI under 10.4 (Applescript 1.10.7)
thank your every one!
Model: G4 PCI
AppleScript: 1.10.7
Operating System: Mac OS X (10.4)
Ok, what you script does right now is it checks to see if the current disks plugged in contain ALL of the USBackXX’s. You only need it to contain one of them. The way I did it was to repeat with every USB item thats currently plugged in, check if it’s in your accepted list, if it is it exits the loops. Heres the code:
set disk_list to {"USBack01", "USBack02", "USBack03", "USBack04", "USBack05", "USBack06", "USBack07", "USBack08", "USBack09", "USBack10", "USBack11", "USBack12", "USBack13", "USBack14", "USBack15", "USBack16", "USBack17", "USBack18", "USBack19", "USBack20"}
set shouldRepeat to true
tell application "Finder"
say "insert disk"
repeat until 1 = 2 -- :) We're gonna exit it manually so this isn't important, as long as it's always false
set currentUSBs to name of every disk
repeat with i from 1 to (length of currentUSBs)
if disk_list contains item i of currentUSBs then
set shouldRepeat to false
exit repeat
end if
end repeat
if not shouldRepeat then
exit repeat
end if
end repeat
say "thank you"
end tell
set disk_list to {"USBack01", "USBack02", "USBack03", "USBack04", "USBack05", "USBack06", "USBack07", "USBack08", "USBack09", "USBack10", "USBack11", "USBack12", "USBack13", "USBack14", "USBack15", "USBack16", "USBack17", "USBack18", "USBack19", "USBack20"}
set shouldRepeat to true
tell application "Finder"
repeat
say "insert disk"
set currentUSBs to name of every disk
repeat with i from 1 to (length of currentUSBs)
if disk_list contains item i of currentUSBs then
set shouldRepeat to false
exit repeat
end if
end repeat
if not shouldRepeat then
exit repeat
end if
end repeat
say "thank you"
end tell
just move the say “insert disk” inside of the 1=2 loop, the loop will still exit at the right time, so this would be your final code:
set disk_list to {"USBack01", "USBack02", "USBack03", "USBack04", "USBack05", "USBack06", "USBack07", "USBack08", "USBack09", "USBack10", "USBack11", "USBack12", "USBack13", "USBack14", "USBack15", "USBack16", "USBack17", "USBack18", "USBack19", "USBack20"}
set shouldRepeat to true
tell application "Finder"
repeat until 1 = 2 -- :) We're gonna exit it manually so this isn't important, as long as it's always false
set currentUSBs to name of every disk
repeat with i from 1 to (length of currentUSBs)
if disk_list contains item i of currentUSBs then
set shouldRepeat to false
exit repeat
end if
--set volume 100 (if you want to make it so the volume wont go down, put this in here :))
say "insert disk" --Waits until its confirmed theres still no disk in, then says insert disk
end repeat
if not shouldRepeat then
exit repeat
end if
end repeat
say "thank you"
end tell
And any time man! If you have any other codes you want me to check out, i’ll take a crack at them