Applescript: Setting the User's home pathname?

Discussion in 'Mac Programming' started by Neotyguy40, Dec 30, 2009.

  1. Neotyguy40 macrumors regular

    Joined:
    Jul 15, 2009
    #1
    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.
     
  2. dmmcintyre3 macrumors 68020

    Joined:
    Mar 4, 2007
    #2
    ~/ is the root of the current users home directory
     
  3. Neotyguy40 thread starter macrumors regular

    Joined:
    Jul 15, 2009
    #3
    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
     
  4. seepel macrumors 6502

    seepel

    Joined:
    Dec 22, 2009
    #4
    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.
     
  5. Neotyguy40 thread starter macrumors regular

    Joined:
    Jul 15, 2009
    #5
    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.
     
  6. mysterytramp macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #6
    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
     
  7. Neotyguy40 thread starter macrumors regular

    Joined:
    Jul 15, 2009
    #7
    Ahh, thanks! That works perfectly!
     

Share This Page