How to copy/paste one or more files in AppleScript? - applescript

i've created an AppleScript that allows me to create a folder in my computer in a desired location:
Here is the script:
set folderName to text returned of (display dialog "Please enter Folder Name:" default answer "Folder_Name")
set loc to choose folder "Choose Parent Folder Location"
tell application "Finder"
set newfolder to make new folder at loc with properties {name:folderName}
end tell
What I want now, is it possible to copy and paste files (template) in this folder that i just created with my AppleScript?
The files (template) would be placed in the same folder as the AppleScript.
And also, is it possible to create an app with my script and put the files (template) in content folder of app for works properly?
PS: I'm a newbies in AppleScript, my code in the current state it is good?

All this is possible. But I'm not sure I have understand all quite correct.
To create and AppleScript Application in AppleScript Editor and show the Resources Folder:
Choose Save.
In the save Dialog choose your save destination.
Choose File Format: Application.
Click Save.
Navigate to the App in Finder, right click it and select "Show Package Content".
The opened folder will contain a folder named Contents in this there is the Resources folder. Put the files there or create them there.
To get the path to this folder use:
set resPath to (path to me as text) & "Contents:Resources:"
(The above script won't work as excepted in AppleScript Editor. You have to run the script as an app)(Seems that you can now test this out of Script Editor)
You can now copy your template files like this:
set resPath to (path to me as text) & "Contents:Resources:"
tell application "Finder" to duplicate resPath & "aTemplate.txt" to loc
BTW: You can access the Resources folder directly via the Scrip Editor if you click Bundle Contents in the toolbar.

Related

Transfer Music file from USB into "Automatically Add to iTunes" and play it with Applescript

I need a script that moves a music file from my USB Music folder into the "Automatically Add to iTunes" folder, and then plays that file. This is what I have so far:
tell application "Finder"
move items from "LEXAR:Pictures:Music:" to "Macintosh HD:User:" --this is where i'm lost, i need the path that doesnt include my name as the User
--and i need some way to tell itunes to play that file
sorry about the weird code setup. What I want to happen is I insert my USB into someone's computer, click on this script as an .app, and it will transfer the files in my USB under "Music" into the "Automatically Add to iTunes" and then launching iTunes, playing that music file.
You can use this:
tell application "Finder"
set userPath to (path to home folder as text)
set directoryPath to "Music:iTunes:iTunes Media:Automatically Add to iTunes"
set fullPath to userPath & directoryPath
move every file of folder "LEXAR:Pictures:Music:" to folder fullPath
end tell
and then use that variable in order to get to the home folder of the currently logged in user. From there, you can reference the Automatically Add to iTunes folder :)

Mac Automator: Mass-create Subfolders

I am trying to use Automator to take a bunch of previously-created folders and create two new folders within each one, an "Originals" folder and a "Scans" folder. I would like to be able to drag or select the folders that need the subfolders and then have the action run automatically.
I've tried making both an action and a service to add the subfolders, but when I select multiple folders, it only runs once.
Here is a screenshot of what I've done so far...
Try saving the workflow as an Application:
Save the Application to your Desktop, then you can drop folders there whenever you want.
Here is an AppleScript that, when Exported as an Application, functions as a Droplet to make the desired folders in every folder dropped thereon:
on open droppings
repeat with everyDrop in droppings
if (info for everyDrop)'s folder is true then
--make two folders
tell application "Finder"
make new folder at (everyDrop as text) with properties {name:"Originals"}
make new folder at (everyDrop as text) with properties {name:"Scans"}
end tell
end if
end repeat
end open
on run
display dialog "Drop some folders here to add Originals and Scans folders" buttons {"Aye Aye"} default button "Aye Aye"
end run

moving one folder to another folder - applescript

I'm trying to move a user-selected folder to another folder, but I don't get it: whenever I look it up, it looks too complicated, even though I know it's not supposed to be.
Here's the code I have so far - please help:
choose folder with prompt "Select folder:"
on open of finderObject
tell application "Finder" to move (finderObject) to folder "Library:Application Support"
end open
end
First off, you have to assign the chosen folder to a variable.
Also, many special folders in the OSX file structure have special names to get their paths, including the library and the application support folders. So, your script can simply be:
set finderObject to choose folder with prompt "Select folder:"
tell app "Finder" to move finderObject to folder (path to Application Support folder from local domain as string)
However, that is the root level Library folder. I suspect you will want to use the Application Support folder in the ~/ user domain. For that, change the "from local domain" to "from user domain".

Auto scripting two folders with the same name, but 1 folder appended with a prefix

I’m new to the forum and relatively new to scripting and wanted to ask a question.
I’m trying to script a workflow where when prompted, users create a folder and when the script executes, a dialogue pops up. Users name the folder, for example; NewFolder1, it is then saved in a directory. Another folder is then created in the background, into another directory with the same name created by the user earlier, but appended with a prefix, for example; Name_ NewFolder1.
I then want sub folders created in each directory as well as alias folders which point to Name_ NewFolder1 created in the original (NewFolder1) directory
I'm on a mac and I can do most of this via applescript or automator but am stuck on the initial creating 'NewFolder1' and 'Name_ NewFolder1' at the same time in the two separate directories.
I only want to prompt the user to name one folder rather than show them two dialogues for 'NewFolder1' and 'Name_ NewFolder1'
Does anyone have any ideas of how i can achieve this? Either via a shell, applescript or UNIX
Thank you
Here's how to do the part you're stuck on in AppleScript:
set folder_name to text returned of (display dialog "What is the folder name?" default answer "untitled")
set second_name to "Name_" & folder_name
tell application "Finder"
make new folder at desktop with properties {name:folder_name}
make new folder at desktop with properties {name:second_name}
end tell
`set client_name to text returned of (display dialog "Create Folders:" default answer "Type here")
set loc1 to ":path1"
set loc2 to ":path2"
set clientmedia_name to "name_" & client_name
tell application "Finder"
make new folder at loc2 with properties {name:clientmedia_name}
set new to make new folder at loc1 with properties {name:client_name}
make new folder at new with properties {name:"1"}
make new folder at new with properties {name:"2"}
make new folder at new with properties {name:"3"}
make new folder at new with properties {name:"4"}
end tell`
This is how far i have got, but can't seem to create folders in the clientmedia_name dir
Thanks,

How do I use applescript to name a folder by pasting from the clipboard

I work in graphic design and want to create an script for indesign that will automatically:
open a specified document template.
Create a new project folder.
Name that folder with text from the clipboard.
Save the newly opened document to the newly created folder and name that document with the same text from the clipboard.
I am very new to Applescript so type very slowly and use small words so that I can understand.
Here is what I have come up with in the way of code so far:
tell application "Adobe InDesign CS5"
set myDocument to open "cm:Graphic_Design:Design Studio Templates:Brochure_042012_001:Brochure_042012_001.indt"
end tell
tell application "Finder"
make new folder at folder "Work" of folder "Graphic_Design" of disk "cm" with properties {name:"untitled folder"}
set name of folder "untitled folder" of folder "Work" of folder "Graphic_Design" of disk "cm" to pbpaste
end tell
Try:
tell application "Finder" to set newFolder to make new folder at "cm:Graphic_Design:Work" with properties {name:(the clipboard as text)}
tell application "Adobe InDesign CS5"
tell active document to save saving in (newFolder as text)
end tell

Resources