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

CountrySeacow

macrumors newbie
Original poster
Dec 7, 2012
8
0
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
 

andmr

macrumors member
Aug 25, 2008
31
0
NE Florida
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
 

CountrySeacow

macrumors newbie
Original poster
Dec 7, 2012
8
0
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

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"
 
Last edited:

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
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.
 

Attachments

  • Picture 3.png
    Picture 3.png
    17.9 KB · Views: 82

CountrySeacow

macrumors newbie
Original poster
Dec 7, 2012
8
0
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.

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:
https://forums.macrumors.com/threads/1503702/
Thanks again!
 

CountrySeacow

macrumors newbie
Original poster
Dec 7, 2012
8
0
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.

Alright, question for you kryten2. What if i want to reference the ApplicationSupport folder using "(path to desktop as text) & "FolderA""
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Hey, does that "(path to desktop as text) apply when ever you are trying to connect to the desktop?

Yes

What if i want to reference the ApplicationSupport folder

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
 

Attachments

  • Picture 4.png
    Picture 4.png
    59.7 KB · Views: 88

CountrySeacow

macrumors newbie
Original poster
Dec 7, 2012
8
0
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

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.
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
As you noticed there's usually more than one way to accomplish what you want. Use whatever you think is the easiest for you.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.