I’m using a short script which activates Toast & burns DVD’s for me . . . I have two problems which are posing small problems, so as a novice AppleScripter, I’d like to ask for some help with these individually.
The first issue relates to icons which Toast seems to leave behind.
After burning several DVD’s I notice that (sometimes) Toast leaves several “Untitled DVD” icons on the desktop. I’d like to ensure that if these are present, the script checks for these and removes them on each script activation.
I’ve been checking these forums for something like:
Tell finder
find files of type (.xxx) on (path to desktop)
erase & empty trash
end tell
Please excuse the scripting, as I don’t have my reference book with me while writing this post!
Any help with this first issue would be very much appreciated.
set desktopPath to path to desktop folder
tell application "Finder"
set dItems to items of desktopPath
repeat with anItem in dItems
if name of anItem contains "Untitled DVD" then
move anItem to trash
end if
end repeat
end tell
display dialog "Do you want me to empty the trash for you?" buttons {"Cancel", "Empty Trash"} default button 1 with icon 2
if button returned of result is "Empty Trash" then
tell application "Finder" to empty trash
end if
I’d like to ensure the end script is as streamlined as possible, and will try to integrate your idea’s into it.
Much better to have less than more I suspect, but at this stage I’m a novice and am experimenting with things to see how the jigsaw fits together.
One issue I’m coming across, and have yet to work out, is the path problem, where I can get my script to work (partially at this stage) on my own machine, but I’m not understanding the scripting sufficiently enough to work out how to make the script work on any machine (though this may work to my advantage I guess)!
Thanks for the input, it’s fascinating trying to get this to work!
That’s why I wrote my script the way I did. For beginners I like to show a step at a time so they can learn techniques that will work in almost all situations. For Nigel I certainly would have written the script differently. The desktop path I showed will work in any application. The repeat loop too although it’s even safer to use “repeat with i from 1 to (count of something)” so I probably should have shown that instead. When I began “whose” filters were hard for me to get the hang of because they worked in some applications and not others. Actually I still struggle with them sometimes.
The Finder has the keywords ‘startup disk’, ‘home’, and ‘desktop’, which refer respectively to the startup disk of the machine on which the script’s running, the home folder of the user in which the script’s running, and the user’s desktop folder.
Hank used ‘path to’, which is a command from the StandardAdditions OSAX (part of the standard AppleScript installation). That has a lot more options, on which I won’t give a full tutorial here!
Both save the scripter having to know the names of the startup disk and user in advance. Feel free to ask again when you get to that point.
Thanks for the input . . . . as a novice I’m aware of chmod, but have no idea how I’d implement this into a script at this stage of my learning I’m afraid.
Would you be able to go through the steps I need to take to insert the shell scripts you describe.
Well, the paths contain stars, so that wouldn’t work in AppleScript’s do shell script.
But you can list a folder’s contents without the help of any other application, and process the list
on run
set desktopFolder to path to desktop folder
set desktopContents to list folder desktopFolder
repeat with i in desktopContents
if i contains "Untitled DVD" then
set fullItemPath to (desktopFolder as text) & i
do shell script "mv " & quoted form of POSIX path of fullItemPath & " ~/.trash" -- move to trash
--do shell script "rm " & quoted form of POSIX path of fullItemPath -- delete immediately
end if
end repeat
end run
Hope it helps,
ief2
PS: In the script, unquote one of the do shell script-lines.