Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 7, 2012, 06:42 PM   #1
CountrySeacow
macrumors newbie
 
Join Date: Dec 2012
ApplescriptEditor; Renaming folders

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
CountrySeacow is offline   0 Reply With Quote
Old Dec 7, 2012, 08:46 PM   #2
andmr
macrumors member
 
Join Date: Aug 2008
Location: 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
andmr is offline   0 Reply With Quote
Old Dec 8, 2012, 11:44 AM   #3
CountrySeacow
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Quote:
Originally Posted by andmr View Post
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 by CountrySeacow; Dec 9, 2012 at 02:44 PM.
CountrySeacow is offline   0 Reply With Quote
Old Dec 9, 2012, 04:10 PM   #4
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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.
Attached Thumbnails
Click image for larger version

Name:	Picture 3.png
Views:	1
Size:	17.9 KB
ID:	382534  
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Dec 9, 2012, 05:29 PM   #5
CountrySeacow
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Quote:
Originally Posted by kryten2 View Post
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:
http://forums.macrumors.com/showthread.php?t=1503702
Thanks again!
CountrySeacow is offline   0 Reply With Quote
Old Dec 9, 2012, 05:53 PM   #6
CountrySeacow
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Quote:
Originally Posted by kryten2 View Post
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""
CountrySeacow is offline   0 Reply With Quote
Old Dec 10, 2012, 03:48 PM   #7
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Quote:
Hey, does that "(path to desktop as text) apply when ever you are trying to connect to the desktop?
Yes

Quote:
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/...983-CH216-SW18
Attached Thumbnails
Click image for larger version

Name:	Picture 4.png
Views:	3
Size:	59.7 KB
ID:	382771  
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Dec 10, 2012, 04:16 PM   #8
CountrySeacow
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Quote:
Originally Posted by kryten2 View Post
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/...983-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.
CountrySeacow is offline   0 Reply With Quote
Old Dec 11, 2012, 12:04 PM   #9
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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.
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Dec 11, 2012, 04:57 PM   #10
CountrySeacow
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
Quote:
Originally Posted by kryten2 View Post
As you noticed there's usually more than one way to accomplish what you want. Use whatever you think is the easiest for you.
alright, thanks for your advice!!!
CountrySeacow is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:52 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC