PDA

View Full Version : I want to make AppleScript Create Folder




DavidBlack
Feb 3, 2013, 03:11 PM
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



chown33
Feb 3, 2013, 04:35 PM
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
Feb 3, 2013, 04:40 PM
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
Feb 3, 2013, 05:01 PM
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
Feb 3, 2013, 05:50 PM
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.


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

Comeagain?
Feb 3, 2013, 06:05 PM
Is this for interacting with iCloud? If so, Apple has specific documentation on how to do that.

DavidBlack
Feb 3, 2013, 07:17 PM
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

kryten2
Feb 3, 2013, 07:25 PM
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 :

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
Feb 3, 2013, 08:04 PM
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 :

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
Feb 4, 2013, 06:22 AM
Try this :

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

DavidBlack
Feb 4, 2013, 01:07 PM
Try this :

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
Feb 4, 2013, 03:34 PM
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 :


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

kryten2
Feb 4, 2013, 03:57 PM
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 :

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
Feb 4, 2013, 04:08 PM
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 :

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

kryten2
Feb 4, 2013, 04:28 PM
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 :

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
Feb 4, 2013, 04:37 PM
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 :

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
Feb 4, 2013, 05:06 PM
Try this :

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
Mar 14, 2013, 06:43 AM
Try this :

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
Mar 14, 2013, 03:31 PM
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

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)

DavidBlack
Mar 14, 2013, 04:10 PM
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

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
Mar 14, 2013, 04:17 PM
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

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

kryten2
Mar 14, 2013, 04:51 PM
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.

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"

DavidBlack
Mar 14, 2013, 07:02 PM
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.

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.

chown33
Mar 14, 2013, 07:21 PM
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:
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:
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:
& " -image " &
but in yours:
& "-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
Mar 15, 2013, 02:43 PM
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:
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:
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:
& " -image " &
but in yours:
& "-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
Mar 15, 2013, 02:52 PM
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.

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"

Just one more question I won't bother you again I want the action.icns and the setFileIcon to be in a applications resources but when I place the path it does it work .

kryten2
Mar 15, 2013, 04:32 PM
Just one more question I won't bother you again I want the action.icns and the setFileIcon to be in a applications resources but when I place the path it does it work .

Yes.

set exePath to path to resource "SetFileIcon"
set imagePath to path to resource "Actions.icns"

DavidBlack
Mar 15, 2013, 06:18 PM
Yes.

set exePath to path to resource "SetFileIcon"
set imagePath to path to resource "Actions.icns"


YES thanks for your reply but this looks like it applies when making application with applescript editor.I am adding the setIconFile and icon file to my xcode project then when I click a button it would execute the applescript

NSString* path = [[NSBundle mainBundle] pathForResource:@"icons change" ofType:@"scpt"];
NSURL* url = [NSURL fileURLWithPath:path];NSDictionary* errors = [NSDictionary dictionary];
NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
[appleScript executeAndReturnError:nil];


Thats the code in Xcode can you help me?