Ok I used a previous example to make this code but it isn't working

What I’m trying to do is delete a folder and all its contents at this location.

/Macintosh HD/Library/InputManagers/CTLoader/

"CTLoader is the folder I’m trying to kill, I put a test one at that location but my script isn’t touching it at all.
I need your savvy and wisdom my masters!

tell application “System Events”
set libraryFolder to path to library folder
end tell

try
tell application “Finder”
if exists folder “CTLoader” of libraryFolder then
delete folder “CTLoader” of libraryFolder
end if
end tell
end try

BigJack Thanks! OS X 10.9.5

works fine here under OSX10.9.5, without administrator privileges, I had to type my password in, thats all

edit: oops over looked the other folder, so you need as posted by kel1

Hi BigJack,

Your path /Macintosh HD/Library/InputManagers/CTLoader/ has the InputManagers folder in between. You need to be precise when using references.

Edited: so you can write:
folder “CTLoader” of folder “InputManagers” of libraryFolder

gl,
kel

Ok I tried that and there is no error but it deletes nothing. Here is were I’m at.

try
tell application “Finder”
if exists folder “CTLoader” of folder “InputManagers” of libraryFolder then
delete folder “CTLoader” of folder “InputManagers” of libraryFolder
end if
end tell
end try

Thanks BigJack

Hi BigJack,

Try this:

try
    tell application "Finder"
        if exists folder "CTLoader" of folder "InputManagers" of libraryFolder then
		beep
            delete folder "CTLoader" of folder "InputManagers" of libraryFolder
        end if
    end tell
end try

For troubleshooting see if it beeps.

gl,
kel

Also, one other thing is that if you use the try/error/end try block without the error part then it doesn’t tell you anything. Here’s an example of using the error block:

try
	display dialog "hello"
	display dialog "user didn't cancel"
on error err_msg
	display dialog err_msg
end try

If it errors then you’ll know it.

gl,
kel

If you check the existence of a folder, a try block is not needed


set libraryFolder to path to library folder

tell application "Finder"
	if exists folder "InputManagers:CTLoader" of libraryFolder then
		delete folder "InputManagers:CTLoader" of libraryFolder
	end if
end tell


Just semantics, but you should end the folder path with colon. Another interesting way to find if something exists is to coerce to alias reference.

Interesting subject. I wonder why BigJack can’t delete that folder. Please write back!

There was no beep so it is not finding the folder I must be doing something wrong?

tell application “System Events”
set libraryFolder to path to library folder
end tell

tell application “Finder”
if exists folder “InputManagers:CTLoader:” of folder of libraryFolder then
beep
delete folder “InputManagers:CTLoader:” of folder of libraryFolder
end if
end tell

BigJack sad Applescript is good when it works!

Hi BigJack,

Your script does not look right.

tell application "Finder"
    if exists folder "InputManagers:CTLoader:" of folder of libraryFolder then
        beep
        delete folder "InputManagers:CTLoader:" of folder of libraryFolder
    end if
end tell

of folder of libraryFolder does not look right. There’s an extra of folder in there.

Edited: don’t worry. I know how it is when you’re rushing to do something.

Edited: also, you are getting many different inputs.

Edited: what you can do to get a good reference is to use something like:

choose folder

or:

choose file

You can then use that reference. Later on, you can use more advanced stuff once you get it working.

gl,
kel

For instance, one of the simplest forms might be this:

set theFolder to choose folder
tell application "Finder" to delete theFolder

This should move the folder to the trash. You can just use the ‘choose folder’ command to see how an alias reference would look also.

Edited: btw, AppleScript references always give people troubles at the beginning.

gl,
kel

That was the problem thanks Kel!