ApplescriptEditor; Renaming folders

Discussion in 'Mac Programming' started by CountrySeacow, Dec 7, 2012.

  1. macrumors newbie

    Joined:
    Dec 7, 2012
    #1
    Hello applescript users!
    There is most likely a very simple answer to this, but i cannot find code that allows you to tell applescript to change the name of "FolderA" to "BFolder" (as an example).
    Here is a sample scenario that i want to use it in:
    Code:
    tell application "Finder"
    	activate
    	if exists folder "Macintosh HD:Users:USERNAME:Library:Application Support:FolderA" then
    --(*rename "FolderA" to "BFolder"*)
    	else
    --(*ETC*)
    	end if
    end tell
    
    Where
    -- (*TEXTHERE*)
    is just there to note what i want there. The (*ETC*) is other code that is unnecessary in the scenario.
    Thanks everyone!
    CountrySeacow
     
  2. macrumors member

    Joined:
    Aug 25, 2008
    Location:
    NE Florida
    #2
    Hi, try this:

    Code:
    tell application "Finder"
    	set x to "Macintosh HD:Users:USERNAME:Library:Application Support:FolderA"
    	if exists folder x then
    		set name of folder x to "BFolder"
    	else
    		--(*ETC*)
    	end if
    end tell
     
  3. CountrySeacow, Dec 8, 2012
    Last edited: Dec 9, 2012

    thread starter macrumors newbie

    Joined:
    Dec 7, 2012
    #3
    hmm. I dont know if the "set name to" function for that works because it cant find the folder, even though it exists.
    I tried using the following code, with "FolderA" present on the desktop
    Code:
    tell application "Finder"
    	set x to "Macintosh HD:Users:USERNAME:Desktop:FolderA"
    	if exists folder x then
    		set name of folder x to "BFolder"
    	else
    		display dialog "it doesnt exist"
    	end if
    end tell
    
    any advice?
    it will either tell my it cant make "Macintosh HD:Users:USERNAME:Desktop:FolderA" into type, or it will say "it doesnt exist"
     
  4. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    Try this :

    Code:
    tell application "Finder"
    	set x to (path to desktop as text) & "FolderA"
    	if exists folder x then
    		set name of folder x to "BFolder"
    	else
    		display dialog "it doesnt exist"
    	end if
    end tell
    Post a screenshot of the Event Log when you run the script in the Script Editor.
     

    Attached Files:

  5. thread starter macrumors newbie

    Joined:
    Dec 7, 2012
    #5
    YAY! Yours worked!!! Thanks!
    Hey, does that "(path to desktop as text) & "FolderA"" apply when ever you are trying to connect to the desktop? I have another thread on that.
    Here my other thread:
    http://forums.macrumors.com/showthread.php?t=1503702
    Thanks again!
     
  6. thread starter macrumors newbie

    Joined:
    Dec 7, 2012
    #6
    Alright, question for you kryten2. What if i want to reference the ApplicationSupport folder using "(path to desktop as text) & "FolderA""
     
  7. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #7
    Yes

    Depends on which Application Support folder you want to reference :

    Code:
    path to application support from user domain
    path to application support from local domain
    Info : https://developer.apple.com/library/mac/#documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW18
     

    Attached Files:

  8. thread starter macrumors newbie

    Joined:
    Dec 7, 2012
    #8
    alright, well while reading a tutorial on applescript as a whole, I discovered i could just say:
    Code:
    set x to folder "Application Support" of folder "Library" of home
    
    I replaced "folder "USERNAME" of folder "Users" of startup disk" with "home"

    Do you see anything wrong with that statement, or will it usually work. So far it has worked with me, but im just a novice.
     
  9. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #9
    As you noticed there's usually more than one way to accomplish what you want. Use whatever you think is the easiest for you.
     
  10. thread starter macrumors newbie

    Joined:
    Dec 7, 2012
    #10
    alright, thanks for your advice!!!
     

Share This Page