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

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,423
A sea of green
Try google search terms:
applescript make new folder

If the found results don't answer your question, then ask again, providing more details. I don't have a "Mobile Document" folder on my disk, and since you didn't tell us where yours is located, you'll have to be more specific. Tell us exactly where you want the new folder to be created, and what you want its name to be.
 

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Try google search terms:
applescript make new folder

If the found results don't answer your question, then ask again, providing more details. I don't have a "Mobile Document" folder on my disk, and since you didn't tell us where yours is located, you'll have to be more specific. Tell us exactly where you want the new folder to be created, and what you want its name to be.

OK if a applescript wont work. I want my app to right a file to a folder when the button is pressed. How can I do that?
 

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,423
A sea of green
OK if a applescript wont work. I want my app to right a file to a folder when the button is pressed. How can I do that?

Where did I say an AppleScript won't work? Where does any of the search results say that it's impossible to have an AppleScript make a new folder?

Post the code you have now. If you don't have any code, tell us what tutorial or reference you're learning AppleScript from. Be specific: URL of tutorial, or title, author, and edition of book.

If you're not learning AppleScript from a guided source like a tutorial or book, what are you learning from? If you don't know the fundamentals, you won't be able to write anything yourself. All you can do is paste together bits and pieces you find.
 

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Where did I say an AppleScript won't work? Where does any of the search results say that it's impossible to have an AppleScript make a new folder?

Post the code you have now. If you don't have any code, tell us what tutorial or reference you're learning AppleScript from. Be specific: URL of tutorial, or title, author, and edition of book.

If you're not learning AppleScript from a guided source like a tutorial or book, what are you learning from? If you don't know the fundamentals, you won't be able to write anything yourself. All you can do is paste together bits and pieces you find.


Code:
tell application "Finder"
	set p to (path to) Macintosh HD:Users:Desktop-- Or whatever path you want
	make new folder at p with properties {name:"New Folder"}
end tell



The problem is if I have the directory for the app program for my computer if a other user uses it it won't work. I want the AppleScript to work on any computer
 
Last edited by a moderator:

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
For example let's say you want to make a new folder on the desktop.
You haven't changed the name of your startup disk and your username is david then the following code :

Code:
path to desktop

will give a result of : alias "Macintosh HD:Users:david:Desktop:"

If you run this on another mac where you changed the name of the startup disk to MyBigDisk and you log on with the username black then the same code will give a result of : alias "MyBigDisk:Users:black:Desktop:"

Info about the path to (folder) command and the special folder for which to return the path on this link : https://developer.apple.com/library/mac/#documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW19

You'll find it in the Commands Reference section. Or perhaps the path to resource might be of use to you as well.
 

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
For example let's say you want to make a new folder on the desktop.
You haven't changed the name of your startup disk and your username is david then the following code :

Code:
path to desktop

will give a result of : alias "Macintosh HD:Users:david:Desktop:"

If you run this on another mac where you changed the name of the startup disk to MyBigDisk and you log on with the username black then the same code will give a result of : alias "MyBigDisk:Users:black:Desktop:"

Info about the path to (folder) command and the special folder for which to return the path on this link : https://developer.apple.com/library/mac/#documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW19

You'll find it in the Commands Reference section. Or perhaps the path to resource might be of use to you as well.
Ok Thanks a lot! But say I want the folder to be created in the ~/Libary folder how would I write that in AppleScript?
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Try this :

Code:
tell application "Finder"
	set p to path to library folder from user domain
	make new folder at p with properties {name:"New Folder"}
end tell
 

Attachments

  • Picture 2.png
    Picture 2.png
    69 KB · Views: 908
  • Picture 1.png
    Picture 1.png
    59.6 KB · Views: 782

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Ok. Thanks how to place the path into the user mobile documents folder?

what would the code look like if i try to place it i Mobile Documents I tried :

Code:
tell application "Finder"
	set p to path to mobiledocuments folder from user domain
	make new folder at p with properties {name:"New Foldergyg11tr"}
end tell
but i does not work
 
Last edited by a moderator:

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
What is this "Mobile Document" folder? I know I don't have it on my disk. The question has been asked already but you haven't provided an answer. Have you looked at the link I provided? Do you see any reference to the mobiledocuments folder in the special folder for which to return the path. Maybe I skipped over it but I just checked and it is not there so this :

Code:
set p to path to mobiledocuments folder from user domain

isn't going to work. It seems like you're pasting together bits and pieces you find, hoping it will work. As you noticed things start to fail pretty quick by doing this. Please provide more information, post a screenshot of the location of this mysterious "Mobile Document" folder or continue what you've been doing without success.
 

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
What is this "Mobile Document" folder? I know I don't have it on my disk. The question has been asked already but you haven't provided an answer. Have you looked at the link I provided? Do you see any reference to the mobiledocuments folder in the special folder for which to return the path. Maybe I skipped over it but I just checked and it is not there so this :

Code:
set p to path to mobiledocuments folder from user domain

isn't going to work. It seems like you're pasting together bits and pieces you find, hoping it will work. As you noticed things start to fail pretty quick by doing this. Please provide more information, post a screenshot of the location of this mysterious "Mobile Document" folder or continue what you've been doing without success.


Mobile Documents is a folder you have when you have iCloud. I want to make applescript make the folder in ~/Library/Mobile Documents
 

Attachments

  • mobile docs.png
    mobile docs.png
    1.1 MB · Views: 591

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Unfortunately I don't have/use ICloud so I don't know if you're allowed to create folders in that Mobile Documents folder but you can try this :

Code:
tell application "Finder"
	set p to (path to library folder from user domain as text) & "Mobile Documents:"
	make new folder at p with properties {name:"TEST"}
end tell
 

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Unfortunately I don't have/use ICloud so I don't know if you're allowed to create folders in that Mobile Documents folder but you can try this :

Code:
tell application "Finder"
	set p to (path to library folder from user domain as text) & "Mobile Documents:"
	make new folder at p with properties {name:"TEST"}
end tell

Thanks so much it works! But on more question I want it to also take the folder it just created and make alias in the Home folder
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Try this :

Code:
tell application "Finder"
	set p to (path to library folder from user domain as text) & "Mobile Documents:"
	try
		set newFolder to make new folder at p with properties {name:"TESTING"}
		make new alias at (path to home folder) to newFolder
	on error the error_message number the error_number
		display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
	end try
end tell
 

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Try this :

Code:
tell application "Finder"
	set p to (path to library folder from user domain as text) & "Mobile Documents:"
	try
		set newFolder to make new folder at p with properties {name:"TESTING"}
		make new alias at (path to home folder) to newFolder
	on error the error_message number the error_number
		display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
	end try
end tell

thanks one more question how do you make applescript add a icon to the folder. I search google but found nothing I want applescript after it created the folder to add a icns file to the folder
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Info : http://www.google.be/search?client=safari&rls=en&q=applescript+set+folder+icon&ie=UTF-8&oe=UTF-8&redir_esc=&ei=gSFCUaKuFOec0QXMhICgCQ
http://macscripter.net/viewtopic.php?id=36587
http://www.hamsoftengineering.com/codeSharing/SetFileIcon/SetFileIcon.html

Code:
set exePath to (path to home folder as text) & "SetFileIcon"
set imagePath to (path to desktop folder as text) & "Actions.icns"
tell application "Finder"
	set p to (path to library folder from user domain as text) & "Mobile Documents:"
	try
		set newFolder to make new folder at p with properties {name:"TESTING"}
		make new alias at (path to home folder) to newFolder
	on error the error_message number the error_number
		display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
	end try
end tell
do shell script quoted form of POSIX path of exePath & " -image " & quoted form of POSIX path of imagePath & " -file " & quoted form of POSIX path of (newFolder as text)
 

Attachments

  • Screen shot 2013-03-14 at 21.28.02.png
    Screen shot 2013-03-14 at 21.28.02.png
    75.8 KB · Views: 422
  • Screen shot 2013-03-14 at 21.24.40.png
    Screen shot 2013-03-14 at 21.24.40.png
    68.8 KB · Views: 357
  • Screen shot 2013-03-14 at 21.24.24.png
    Screen shot 2013-03-14 at 21.24.24.png
    86.1 KB · Views: 407
Last edited:

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Info : http://www.google.be/search?client=safari&rls=en&q=applescript+set+folder+icon&ie=UTF-8&oe=UTF-8&redir_esc=&ei=gSFCUaKuFOec0QXMhICgCQ
http://macscripter.net/viewtopic.php?id=36587
http://www.hamsoftengineering.com/codeSharing/SetFileIcon/SetFileIcon.html

Code:
set exePath to (path to home folder as text) & "SetFileIcon"
set imagePath to (path to desktop folder as text) & "Actions.icns"
tell application "Finder"
	set p to (path to library folder from user domain as text) & "Mobile Documents:"
	try
		set newFolder to make new folder at p with properties {name:"TESTING"}
		make new alias at (path to home folder) to newFolder
	on error the error_message number the error_number
		display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
	end try
end tell
do shell script quoted form of POSIX path of exePath & " -image " & quoted form of POSIX path of imagePath & " -file " & quoted form of POSIX path of (newFolder as text)

Hi Thanks for the tip but i am getting SYNTax error
 

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Info : http://www.google.be/search?client=safari&rls=en&q=applescript+set+folder+icon&ie=UTF-8&oe=UTF-8&redir_esc=&ei=gSFCUaKuFOec0QXMhICgCQ
http://macscripter.net/viewtopic.php?id=36587
http://www.hamsoftengineering.com/codeSharing/SetFileIcon/SetFileIcon.html

Code:
set exePath to (path to home folder as text) & "SetFileIcon"
set imagePath to (path to desktop folder as text) & "Actions.icns"
tell application "Finder"
	set p to (path to library folder from user domain as text) & "Mobile Documents:"
	try
		set newFolder to make new folder at p with properties {name:"TESTING"}
		make new alias at (path to home folder) to newFolder
	on error the error_message number the error_number
		display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
	end try
end tell
do shell script quoted form of POSIX path of exePath & " -image " & quoted form of POSIX path of imagePath & " -file " & quoted form of POSIX path of (newFolder as text)
This is the syntax error
 

Attachments

  • Screen Shot 2013-03-14 at 5.09.40 PM.png
    Screen Shot 2013-03-14 at 5.09.40 PM.png
    1.5 MB · Views: 439
  • Screen Shot 2013-03-14 at 5.11.31 PM.png
    Screen Shot 2013-03-14 at 5.11.31 PM.png
    1.1 MB · Views: 439
  • Screen Shot 2013-03-14 at 5.11.26 PM.png
    Screen Shot 2013-03-14 at 5.11.26 PM.png
    1 MB · Views: 412

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Strange. It looks like there is no space between the & and "docs:doc" but it is not really clear. Try with another folder name or type the single set theFolder line in another script editor window and see if it compiles.

Code:
set exePath to (path to home folder as text) & "SetFileIcon"
set imagePath to (path to desktop folder as text) & "Actions.icns"
set theFolder to (path to desktop folder as text) & "docs:doc"
 
Last edited:

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Strange. It looks like there is no space between the & and "docs:doc" but it is not really clear. Try with another folder name or type the single set theFolder line in another script editor window and see if it compiles.

Code:
set exePath to (path to home folder as text) & "SetFileIcon"
set imagePath to (path to desktop folder as text) & "Actions.icns"
set theFolder to (path to desktop folder as text) & "docs:doc"

I am still getting a error.
 

Attachments

  • Screen Shot 2013-03-14 at 7.59.22 PM.png
    Screen Shot 2013-03-14 at 7.59.22 PM.png
    971.5 KB · Views: 374
  • Screen Shot 2013-03-14 at 7.59.28 PM.png
    Screen Shot 2013-03-14 at 7.59.28 PM.png
    987.7 KB · Views: 402

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,423
A sea of green
I am still getting a error.

You're getting an error because you didn't copy and paste the do shell script line exactly as it was posted.

It should be this:
Code:
do shell script quoted form of POSIX path of exePath & " -image " & quoted form of POSIX path of imagePath & " -file " & quoted form of POSIX path of (newFolder as text)

You have this:
Code:
do shell script quoted form of POSIX path of exePath & "-image" & quoted form of POSIX path of imagePath & "-file" & quoted form of POSIX path of theFolder
In your code, you've left out the spaces that are between the quotes.

For example, in the original:
Code:
& " -image " &
but in yours:
Code:
& "-image" &
Look very carefully, because these are not the same. The quoted spaces are required.

And you made the same mistake where you have "-file".
 

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
You're getting an error because you didn't copy and paste the do shell script line exactly as it was posted.

It should be this:
Code:
do shell script quoted form of POSIX path of exePath & " -image " & quoted form of POSIX path of imagePath & " -file " & quoted form of POSIX path of (newFolder as text)

You have this:
Code:
do shell script quoted form of POSIX path of exePath & "-image" & quoted form of POSIX path of imagePath & "-file" & quoted form of POSIX path of theFolder
In your code, you've left out the spaces that are between the quotes.

For example, in the original:
Code:
& " -image " &
but in yours:
Code:
& "-image" &
Look very carefully, because these are not the same. The quoted spaces are required.

And you made the same mistake where you have "-file".


Thanks you guys I got it too work! :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.