I want to make AppleScript Create Folder

Discussion in 'Mac Programming' started by DavidBlack, Feb 3, 2013.

  1. macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #1
    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
     
  2. macrumors 603

    Joined:
    Aug 9, 2009
    #2
    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.
     
  3. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #3
    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?
     
  4. macrumors 603

    Joined:
    Aug 9, 2009
    #4
    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.
     
  5. DavidBlack, Feb 3, 2013
    Last edited by a moderator: Feb 3, 2013

    thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #5

    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
     
  6. macrumors 68020

    Comeagain?

    Joined:
    Feb 17, 2011
    Location:
    Spokane, WA
    #6
    Is this for interacting with iCloud? If so, Apple has specific documentation on how to do that.
     
  7. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #7
    Ok say I Just want to write the file to my desktop when every the user clicks the button
     
  8. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #8
    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.
     
  9. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #9
    Ok Thanks a lot! But say I want the folder to be created in the ~/Libary folder how would I write that in AppleScript?
     
  10. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #10
    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 Files:

  11. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #11
    Ok. Thanks how to place the path into the user mobile documents folder?
     
  12. DavidBlack, Feb 4, 2013
    Last edited by a moderator: Feb 4, 2013

    thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #12
    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
     
  13. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #13
    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.
     
  14. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #14

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

    Attached Files:

  15. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #15
    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
    
     
  16. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #16
    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
     
  17. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #17
    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
    
     
  18. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #18
    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
     
  19. kryten2, Mar 14, 2013
    Last edited: Mar 14, 2013

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #19
    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)
    
     

    Attached Files:

  20. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #20
    Hi Thanks for the tip but i am getting SYNTax error
     
  21. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #21
    This is the syntax error
     

    Attached Files:

  22. kryten2, Mar 14, 2013
    Last edited: Mar 14, 2013

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #22
    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"
     
  23. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #23
    I am still getting a error.
     

    Attached Files:

  24. macrumors 603

    Joined:
    Aug 9, 2009
    #24
    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".
     
  25. thread starter macrumors 6502a

    DavidBlack

    Joined:
    Jan 27, 2013
    Location:
    Somewhere In Apple's HQ ;)
    #25

    Thanks you guys I got it too work! :)
     

Share This Page