Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Neotyguy40

macrumors regular
Original poster
Jul 15, 2009
152
0
Ok, so I am making a small script to delete a certain file that causes an application of mine to crash:

Code:
tell application "Finder"
	set the fileToDelete to alias "Mac HD:Users:Tyler:Library:Preferences:HEAVY Preferences:dyndata.reg"
	delete the fileToDelete
end tell

Anyway, I need to put this on about 70 different computers with different home names. Right now it only works when the user is named Tyler.

I am very bad at Applescript, so I was hoping someone else could tell me how to do this.
 
~/ is the root of the current users home directory

Code:
tell application "Finder"
	set the fileToDelete to alias "~:Library:Preferences:HEAVY Preferences:dyndata.reg"
	delete the fileToDelete
end tell

Doesn't work. I also tried replacing all the colons with slashes:

Code:
tell application "Finder"
	set the fileToDelete to alias "~/Library/Preferences/HEAVY Preferences/dyndata.reg"
	delete the fileToDelete
end tell
 
Code:
set myPath to (path to home folder)

from http://codesnippets.joyent.com/posts/show/519

First hit on googling "applescript home folder". I don't want this to sound like another RTFM (Read the ****ing manual), I'm certainly happy to help and I'm sure others are as well. But that answer came in about 10 seconds using google where as you posted this question about an hour ago. Always try google first, not just for us, but for yourself.
 
Code:
set myPath to (path to home folder)

from http://codesnippets.joyent.com/posts/show/519

First hit on googling "applescript home folder". I don't want this to sound like another RTFM (Read the ****ing manual), I'm certainly happy to help and I'm sure others are as well. But that answer came in about 10 seconds using google where as you posted this question about an hour ago. Always try google first, not just for us, but for yourself.

I did use google. I searched "Getting Home Folder in Applescript", "Home Directory Applescript", and "Using Applescript to get home folder".

EDIT: Infact, that doesn't even do what I need. I want to set the directory to the home folder without needing to edit the script in each one.
 
How's this:

Code:
set fileToDelete to (((path to preferences folder) as text) & "HEAVY Preferences:dyndata.reg") as alias

tell application "Finder"
	delete fileToDelete
end tell

You used an unnecessary "the" which might have helped to make your script unworkable.

And if you're using Snow Leopard, Apple says you should keep commands outside of tell blocks as much as possible. The "path to" command is standard AS, so it doesn't need to be inside the tell block. It's probably not a huge deal, but still ...

mt
 
How's this:

Code:
set fileToDelete to (((path to preferences folder) as text) & "HEAVY Preferences:dyndata.reg") as alias

tell application "Finder"
	delete fileToDelete
end tell

You used an unnecessary "the" which might have helped to make your script unworkable.

And if you're using Snow Leopard, Apple says you should keep commands outside of tell blocks as much as possible. The "path to" command is standard AS, so it doesn't need to be inside the tell block. It's probably not a huge deal, but still ...

mt

Ahh, thanks! That works perfectly!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.