The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   Applications (http://hintsforums.macworld.com/forumdisplay.php?f=5)
-   -   Delete from Desktop using Applescript (http://hintsforums.macworld.com/showthread.php?t=56371)

Hal Itosis 01-13-2009 03:56 PM

Quote:

Originally Posted by tlarkin (Post 513093)
Code:

list="$HOME/Desktop/*"
for file in $list
do
        if [[ -e $file ]]
        then
                rm -rf $file
        else
                echo "no files found"
        fi
done

I haven't tested it so it may need tweaking,

Just call me the tweaker!

While that double-bracketed test [[ -e $file ]] eliminates the need to quote the $file variable,
elsewhere in the do loop quotes will likely be needed. So rm -rf $file should be rm -rf "$file"
OTOH, the quotes where list was defined aren't needed: list=$HOME/Desktop/*

Of course, that script (as written anyway) simply deletes everything there,
so it could be shortened by eliminating the looping and testing altogether:

rm -rf ~/Desktop/*

but that won't notify us if the Desktop was empty (of visible items).

tlarkin 01-13-2009 04:07 PM

Quote:

Originally Posted by Hal Itosis (Post 513197)
Just call me the tweaker!

While that double-bracketed test [[ -e $file ]] eliminates the need to quote the $file variable,
elsewhere in the do loop quotes will likely be needed. So rm -rf $file should be rm -rf "$file"
OTOH, the quotes where list was defined aren't needed: list=$HOME/Desktop/*

Of course, that script (as written anyway) simply deletes everything there,
so it could be shortened by eliminating the looping and testing altogether:

rm -rf ~/Desktop/*

but that won't notify us if the Desktop was empty (of visible items).

ok tweaker

Ah you are right the only time I need to quote it is if there are multiple paths to a variable...I think.

Hal Itosis 01-13-2009 11:18 PM

Quote:

Originally Posted by tlarkin (Post 513198)
the only time I need to quote it is if there are multiple paths to a variable...I think.

More along the lines of: "are there spaces in any file's pathname, or not?"
Essentially, we should *always* ensure they are accounted for... somehow.

In the [[ ]] form of test, the shell provides quoting behind the scenes.
Another method is using the ability of some commands to append null
chars (or accept null chars) as the 'filename delimiter'. Most common
being: find blah blah -print0 |xargs -0 blah

We also had a thread somewhere where we removed the 'space' from
the IFS variable (so that newlines became the main delimiter).

fordf1 12-08-2009 04:41 AM

tell application "Finder"

try

delete (every item of folder "Desktop" of folder "user" of folder "Users" of folder "Macintosh HD")

end try

try

delete (every item of folder "Documents" of folder "user" of folder "Users" of folder "Macintosh HD")

end try

try

delete (every item of folder "Downloads" of folder "user" of folder "Users" of folder "Macintosh HD")

end try

empty trash

end tell

i like this script, how can i modify it to select all user except administrator to replace "user" in this scriopt.

fordf1 12-08-2009 05:14 AM

how to select all users except administrator without having to type all the users name under "user" in this script?


All times are GMT -5. The time now is 02:11 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.