syntax questions about my script

I have a few probably noob questions about Apple scripting

  1. in the line
do shell script "rm -R '~/Suitcase Server Fonts/*'"

I am unable to to delete the information in side Suitcase Server Fonts, I think it is because I cant figure out how to make it understand the Space in the name of the directory

2)in the line

 do shell script "rm /applications/QuarkXPress/JAWS/ttemp/*.ps"

there are files in the in the directory called whatever.ps but they are not deleted. and i have no idea why not i hope i just made a mistake

  1. using the try will any of the rm statements that fails end the try statement. If so should i have to make a try for each rm?

  2. Is there a easy way to delete all the sub Dirs in a directory with out deleting the main directory or any of the files in the main directory ( hope that makes sense)

Thanks alot

see below for the full script


try
    do shell script "rm ~/Library/Preferences/com.quark.QuarkXPress.plist"
    do shell script "rm ~/Library/Preferences/com.quark.QuarkCopyDesk.plist"
    do shell script "rm ~/Library/Preferences/com.extensis.suitcase.plist"
    do shell script "rm -R '~/Library/Preferences/Suitcase prefernces/'"
    do shell script "rm -R '~/Suitcase Server Fonts/*'"
    do shell script "rm -R ~/Library/Preferences/Quark"
    do shell script "rm /applications/QuarkXPress/QPS/*"
    do shell script "rm /applications/QuarkCopyDesk/QPS/*"
    do shell script "rm /applications/QuarkXPress/JAWS/ttemp/*.ps"
    do shell script "rm /System/Library/Caches/com.apple.ATS.System.fcache"
    do shell script "rm /System/Library/Caches/com.apple.ATSServer.FODB_System"
    do shell script "rm /System/Library/Caches/fontTablesAnnex"
    do shell script "rm /Library/Caches/com.apple.ATS/501/Classic.fcache"
    do shell script "rm /Library/Caches/com.apple.ATS/501/Local.fcache"
    do shell script "rm /Library/Caches/com.apple.ATS/User.fcache"
    do shell script "rm /Library/Caches/com.apple.ATS/Classic.fodb"
    do shell script "rm /Library/Caches/com.apple.ATS/Local.fodb"
    do shell script "rm /Library/Caches/com.apple.ATS/User.fodb"
    do shell script "rm /Library/Caches/com.apple.ATS/FondResourceCache"
end try










Hi Crash,

  1. try this. if it doesnt work you most likely are going to have to perform the command with administrator priveleges.
do shell script "rm -rf ~/Suitcase\\ Server\\ Fonts/*"
  1. you may need to force the removal -f, or you may have to have elevated privelegs again.
do shell script "rm -rf /Applications/QuarkXPress/JAWS/ttemp/*.ps"
  1. You are correct a failed try will end the routine so perhaps do something like this to avoid a zillion trys…
set remove_commands to {¬
	"rm -f ~/Library/Preferences/com.quark.QuarkXPress.plist", ¬
	"rm -f ~/Library/Preferences/com.quark.QuarkCopyDesk.plist", ¬
	"rm -f ~/Library/Preferences/com.extensis.suitcase.plist", ¬
	"rm -Rf ~/Library/Preferences/Suitcase\\ prefernces/", ¬
	"rm -Rf ~/Suitcase\\ Server\\ Fonts/*", ¬
	"rm -Rf ~/Library/Preferences/Quark", ¬
	"rm -f /applications/QuarkXPress/QPS/*", ¬
	"rm -f /applications/QuarkCopyDesk/QPS/*", ¬
	"rm -f /applications/QuarkXPress/JAWS/ttemp/*.ps", ¬
	"rm -f /System/Library/Caches/com.apple.ATS.System.fcache", ¬
	"rm -f /System/Library/Caches/com.apple.ATSServer.FODB_System", ¬
	"rm -f /System/Library/Caches/fontTablesAnnex", ¬
	"rm -f /Library/Caches/com.apple.ATS/501/Classic.fcache", ¬
	"rm -f /Library/Caches/com.apple.ATS/501/Local.fcache", ¬
	"rm -f /Library/Caches/com.apple.ATS/User.fcache", ¬
	"rm -f /Library/Caches/com.apple.ATS/Classic.fodb", ¬
	"rm -f /Library/Caches/com.apple.ATS/Local.fodb", ¬
	"rm -f /Library/Caches/com.apple.ATS/User.fodb", ¬
	"rm -f /Library/Caches/com.apple.ATS/FondResourceCache"}

repeat with a_command in remove_command
	removeIt(a_command)
end repeat

on removeIt(a_command)
	try
		do shell script a_command
	end try
end removeIt

I would add some logging features though so you know what commands fail (I have an app very similar but written in XCode to provide a graphical feedback =))

  1. yes there is and here is an example.
set base_folder_path to "whatever"
-- if you have not escaped spaces with \\ base folder path then use quoted form of
-- include the * after the base folder path else the base folder itself will be returned in the find command
do shell script "/usr/bin/find " & base_folder_path & "* -type d -print0 | /usr/bin/xargs -0 /bin/rm -rf"

Hope that all helps =)

Here’s something from another thread [Creating and removing directories via command line]:

Thanks for your reply

in the try loop you made ( neat idea btw)

could i do something like


set remove_commands to {¬
   "rm -f ~/Library/Preferences/com.quark.QuarkXPress.plist", ¬
............  
 "rm -f /Library/Caches/com.apple.ATS/FondResourceCache"}

repeat with a_command in remove_command
   removeIt(a_command)
end repeat

on removeIt(a_command)
   try
       do shell script a_command
   end try

[b]( If end try then write a_command to log?)<--------------[/b]
end removeIt

man i forgot all about that thread thanks for reminding me.

Heh, I didn’t notice who started that thread until just now. It was no problem. :wink:

bump

does anyone know how to right a line to the log if the the Try fails?

global logRef

set logRef to ((path to desktop) as Unicode text) & "Script Log.txt"

try
	close access file filepath
end try

set logRef to (open for access file filepath with write permission)
set eof logRef to 0

(*
your normal script including the set remove commands
and the repeat loop
*)

close access logRef

on removeIt(a_command)
	try
		do shell script a_command
	on error errMsr number errNum
		write errNume & tab & errMsg & return to logRef
	end try
end removeIt