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 Feb 3, 2013, 03:11 PM   #1
DavidBlack
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
I want to make AppleScript Create Folder

I want to make applescript to create a folder in Mobile Document How do I do this i search everywhere but Can't find any
DavidBlack is offline   0 Reply With Quote
Old Feb 3, 2013, 04:35 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
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.
chown33 is offline   0 Reply With Quote
Old Feb 3, 2013, 04:40 PM   #3
DavidBlack
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by chown33 View Post
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?
DavidBlack is offline   0 Reply With Quote
Old Feb 3, 2013, 05:01 PM   #4
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by DavidBlack View Post
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.
chown33 is offline   0 Reply With Quote
Old Feb 3, 2013, 05:50 PM   #5
DavidBlack
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by chown33 View Post
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 Nermal; Feb 3, 2013 at 06:27 PM. Reason: added code tags
DavidBlack is offline   0 Reply With Quote
Old Feb 3, 2013, 06:05 PM   #6
Comeagain?
macrumors 68020
 
Comeagain?'s Avatar
 
Join Date: Feb 2011
Location: Spokane, WA
Is this for interacting with iCloud? If so, Apple has specific documentation on how to do that.
__________________
Questions? MRoogle it!
Current iOS 8 "All the little things!"
MR Scavenger Score: 1
Comeagain? is offline   0 Reply With Quote
Old Feb 3, 2013, 07:17 PM   #7
DavidBlack
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by Comeagain? View Post
Is this for interacting with iCloud? If so, Apple has specific documentation on how to do that.
Ok say I Just want to write the file to my desktop when every the user clicks the button
DavidBlack is offline   0 Reply With Quote
Old Feb 3, 2013, 07:25 PM   #8
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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/...983-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.
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Feb 3, 2013, 08:04 PM   #9
DavidBlack
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by kryten2 View Post
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:davidesktop:"

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:blackesktop:"

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/...983-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?
DavidBlack is offline   0 Reply With Quote
Old Feb 4, 2013, 06:22 AM   #10
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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
Attached Thumbnails
Click image for larger version

Name:	Picture 2.png
Views:	31
Size:	69.0 KB
ID:	394388   Click image for larger version

Name:	Picture 1.png
Views:	21
Size:	59.6 KB
ID:	394389  
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Feb 4, 2013, 01:07 PM   #11
DavidBlack
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by kryten2 View Post
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
Ok. Thanks how to place the path into the user mobile documents folder?
DavidBlack is offline   0 Reply With Quote
Old Feb 4, 2013, 03:34 PM   #12
DavidBlack
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by DavidBlack View Post
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 maflynn; Feb 4, 2013 at 04:40 PM. Reason: Added code tags
DavidBlack is offline   0 Reply With Quote
Old Feb 4, 2013, 03:57 PM   #13
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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.
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Feb 4, 2013, 04:08 PM   #14
DavidBlack
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by kryten2 View Post
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
Attached Thumbnails
Click image for larger version

Name:	mobile docs.png
Views:	79
Size:	1.12 MB
ID:	394485  
DavidBlack is offline   0 Reply With Quote
Old Feb 4, 2013, 04:28 PM   #15
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Feb 4, 2013, 04:37 PM   #16
DavidBlack
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by kryten2 View Post
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
DavidBlack is offline   0 Reply With Quote
Old Feb 4, 2013, 05:06 PM   #17
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Mar 14, 2013, 06:43 AM   #18
DavidBlack
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by kryten2 View Post
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
DavidBlack is offline   0 Reply With Quote
Old Mar 14, 2013, 03:31 PM   #19
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Info : http://www.google.be/search?client=s...FOec0QXMhICgCQ
http://macscripter.net/viewtopic.php?id=36587
http://www.hamsoftengineering.com/co...tFileIcon.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)
Attached Thumbnails
Click image for larger version

Name:	Screen shot 2013-03-14 at 21.24.24.png
Views:	9
Size:	86.1 KB
ID:	402488   Click image for larger version

Name:	Screen shot 2013-03-14 at 21.24.40.png
Views:	9
Size:	68.8 KB
ID:	402489   Click image for larger version

Name:	Screen shot 2013-03-14 at 21.28.02.png
Views:	16
Size:	75.8 KB
ID:	402490  

__________________
Space Corps Directive 34124

Last edited by kryten2; Mar 14, 2013 at 04:06 PM.
kryten2 is offline   0 Reply With Quote
Old Mar 14, 2013, 04:10 PM   #20
DavidBlack
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by kryten2 View Post
Info : http://www.google.be/search?client=s...FOec0QXMhICgCQ
http://macscripter.net/viewtopic.php?id=36587
http://www.hamsoftengineering.com/co...tFileIcon.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 is offline   0 Reply With Quote
Old Mar 14, 2013, 04:17 PM   #21
DavidBlack
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by kryten2 View Post
Info : http://www.google.be/search?client=s...FOec0QXMhICgCQ
http://macscripter.net/viewtopic.php?id=36587
http://www.hamsoftengineering.com/co...tFileIcon.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
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2013-03-14 at 5.09.40 PM.png
Views:	32
Size:	1.50 MB
ID:	402500   Click image for larger version

Name:	Screen Shot 2013-03-14 at 5.11.31 PM.png
Views:	20
Size:	1.05 MB
ID:	402501   Click image for larger version

Name:	Screen Shot 2013-03-14 at 5.11.26 PM.png
Views:	22
Size:	1.04 MB
ID:	402502  

DavidBlack is offline   0 Reply With Quote
Old Mar 14, 2013, 04:51 PM   #22
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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"
__________________
Space Corps Directive 34124

Last edited by kryten2; Mar 14, 2013 at 05:08 PM.
kryten2 is offline   0 Reply With Quote
Old Mar 14, 2013, 07:02 PM   #23
DavidBlack
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by kryten2 View Post
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.
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2013-03-14 at 7.59.22 PM.png
Views:	21
Size:	971.5 KB
ID:	402553   Click image for larger version

Name:	Screen Shot 2013-03-14 at 7.59.28 PM.png
Views:	21
Size:	987.7 KB
ID:	402554  
DavidBlack is offline   0 Reply With Quote
Old Mar 14, 2013, 07:21 PM   #24
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by DavidBlack View Post
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".
chown33 is offline   0 Reply With Quote
Old Mar 15, 2013, 02:43 PM   #25
DavidBlack
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Location: Somewhere In Apple's HQ ;)
Quote:
Originally Posted by chown33 View Post
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!
DavidBlack 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

Similar Threads
thread Thread Starter Forum Replies Last Post
How to create sub-mailboxes with Applescript? torchy Mac Programming 14 May 29, 2014 04:21 PM
Applescript to create a smart folder for each tag? feijoada OS X Mavericks (10.9) 0 Mar 7, 2014 09:55 PM
create folders applescript joennie Mac Programming 3 Jul 30, 2013 06:43 PM
Applescript: How do I create custom data types? moonman239 Mac Programming 1 Jan 5, 2013 11:07 PM
Use AppleScript to create a PPI Calculator? TheMTtakeover Mac Programming 1 Dec 26, 2012 10:11 AM

Forum Jump

All times are GMT -5. The time now is 03:29 AM.

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

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