Moving folder with Applescript
I am trying to move the contents of a folder to a new location, but whenever I run the code below it moves the parent folder as well?
(* now move folders from watched folder to new folder location *)
set targetFolder to ((path to desktop folder as Unicode text) & theFolderName) as alias
set workingFolder to ((path to desktop folder as Unicode text) & "watchedFolder") as alias
move contents of workingFolder to targetFolder
Does anybody have any idea what I am doing wrong? How can I move the contents of 'watchedFolder' to 'targetFolder' without moving the 'watchedFolder'
n/a Mac OS X (10.4.9)
What you're doing wrong is clear when you understand a few things about AppleScript.
What you have in targetFolder is an alias - a special kind of object that refers to a disk object (either a file or a folder).
Whenever you ask AppleScript for 'contents' of an object, you'll usually just get that object back. You can see this if you ask AppleScript:
<pre class=command>set workingFolder to ((path to desktop folder as Unicode text) & "watchedFolder") as alias
get contents of workingFolder</pre>
You'll get back something like 'alias "HD:Users:username:Desktop:watchedFolder"'.
(there are specific cases where 'contents of' an object might return different data, but the point is that this is where your script is failing).
In order to reference the files within the folder, you need to be more specific:
<pre class=command>set targetFolder to ((path to desktop folder as Unicode text) & theFolderName) as alias
set workingFolder to ((path to desktop folder as Unicode text) & "watchedFolder") as alias
tell application "Finder"
move every item of workingFolder to targetFolder
end tell</pre>
In this case since you're now targetting the Finder you can deal the the contents of the folder at a file/directory level rather than at an AppleScript object level - in short AppleScript knows only that workingFolder is an alias, but the Finder knows that it's a folder that contains more items.
Similar Messages
-
Create Smart Folder with Applescript?
Hi
Is there a way to create a Smart Folder with Applescript?
many thanks
LJthanks neil.
one other question. once i've made this folder i'll want to use it.
it occurs to me that i might not be able to use the same code to
call the folder after it's been created since, while the date may
be the same, the time won't be.
how do i stored the new folder name as it's being created so that
i can call it later in the script?
thanks again,
BabaG -
Making and opening folder with applescript
I'm trying to create and open a folder with applescript, but my script gives an error...
This is what i've written but can't figure out what i'm doing wrong. I hope you can help me!
tell application "Finder"
activate
set the_folder to "106_WDJZ Eigen Magazine 20pp_Foto"
set myfolder to make new folder at "Press4:10. Specials:N19. WDJZ Eigen Magazine 20pp:F. Foto:" with properties {name:the_folder}
set openmap to (myfolder & the_folder)
end tell
Thank you very much in advanceThank you both for your awnsers. I really appreciate it! I was trying to create a folder (at "Press4:10. Specials:N19. WDJZ Eigen Magazine 20pp:F. Foto:") with a name (106_WDJZ Eigen Magazine 20pp_Foto) and after the folder is created I want the scrpt to open the folder.
The in FileMakerPro (calculated) applescript is now working and look like this:
"tell application \"Finder\"" & ¶ &
"set the_folder to \"" & Editie_standaardgegevens::UitgaveID & "_" & Editie_standaardgegevens::Editienaam_intern & "_Foto" & "\"" & ¶ &
"set sub_folder to \"Press4:10. Specials:" & Editie_standaardgegevens::Editienaam_intern_totaal & ":F. Foto:\"" & ¶ &
"set myfolder to make new folder at sub_folder with properties {name:the_folder}" & ¶ &
"set openfolder to (sub_folder & the_folder & \":\")" & ¶ &
"open folder openfolder" & ¶ &
"activate" & ¶ &
"end tell" -
Simple question about moving files with applescript : Not finisched
I use this script now but the dubble files stays in folder A. I would like to delete the dubble files so the folder is empty after moving. With this script the dubble files keep is folder A.
tell application "Finder"
activate
set this_folder to ("MAC2:A")
set these_files to every file of folder this_folder
move these_files to ("MAC2:B") with replacing
end tellYour script works fine on the same volume. If you are going to another volume (disk or server) a move become a duplicate by nature. You would have to delete the files after duplicate is complete.
After everthing is moved
tell application "Finder"
activate
set this_folder to ("PowerMac:Temp:")
set these_files to every file of folder this_folder
move these_files to ("Server:Backup:") with replacing
delete these_files
end tell
Delete each file as you go
tell application "Finder"
activate
set this_folder to ("PowerMac:Temp:")
set these_files to every file of folder this_folder
repeat with these_file in these_files
move these_file to ("Server:Backup:") with replacing
delete these_file
end repeat
end tell -
How to make new project in existing folder with applescript in Aperture?
I want to create a new project in an existing folder. I've scoured the web for answers to this but I cant find any. The closest I've come is this:
tell application "Aperture"
set imgSel to (get selection)
if imgSel is {} then
error "Please select an image."
else
set pName to name of parent of item 1 of imgSel
set pID to id of parent of item 1 of imgSel
set cID to id of parent of parent of item 1 of imgSel
set cName to name of parent of parent of item 1 of imgSel
set cLoc to folder cName
tell library "Aperture Library"
make new project at cLoc with properties {name:pName}
repeat with i from 1 to count of imgSel
move item i of imgSel to project (pName)
end repeat
end tell
end if
cLoc
end tell
Which returns:
error "Aperture got an error: AppleEvent handler failed." number -10000
Can anyone enlighten me as to what I'm doing wrong here or show me another way to achieve my goal, thanks?when you say 'new project in an existing folder'..... I assume you mean to create a new Project inside of an existing "Blue" folder...?
Easy.... Select (click) the Blue folder you wish a new Project to appear inside > At the top left corner where it says "new" click the drop down arrow and select the project icon and click it.
Easier still > select the Blue folder you wish another Project to appear inside > use 'Command & N' on the keypad and away you go...
If you dont mean the above...? and you want a blue folder inside a blue folder..?
To create a new blue folder use either the 'New' icon again at the top of the library inspector and click the blue folder icon or (Shift & Command & N ) on the keypad. Then select the new blue folder and repeat the process again...... A folder inside a folder..
Couldn't be simpler....
Aperture already provides these simple commands.... I cant imagine why you want to write an 'Applescript Action' for it.... Unless just for the heck of it...??
Regards..... Gerry... -
Opening a .jpeg-file in a folder with Applescript
I am trying to change the names of .jpeg files into the names of the corresponding music albums in a folder.
As far as my knowledge of Applescript goes, the following script should do the job, but it does not open the .jpeg file, i.e. document 1
tell application "FileMaker Pro"
activate
set url_path to cell "bestandspad_cover" of current record
set album_title to cell "album title" of current record & ".jpeg"
end tell
tell application "System Events"
try
open url_path
if not (exists url_path) then
display dialog "not found"
else
display dialog "path=" & url_path
open document 1
--error number -1719 from document 1
set name of document 1 to album_title
display dialog & name of document 1
close document 1 saving yes
end if
end try
end tell
I work in an FMP environment, but that should not bother you. I am using the Applescript editor to simulate the actual situation.
I tried 'open', 'get' and 'getURL', to no avail; in my experience Applescript sometimes requires illogical, or say imaginative solutions.
Do you see one?Thanks for thinking with me.
The problem lies not with FMP; hereafter the Applescript in the editor; I left out the displays, but the content is given in the next line.
==========================
tell application "FileMaker Pro"
activate
set url_path to cell "bestandspad_cover" of current record
--"file://Macintosh HD/Users/apmwulfinghoff/Documents/POPMUZIEK/ALBUM COVERS POP/325.jpeg"
set album_title to cell "album title" of current record & ".jpeg"
--First Ladies Of R&B.jpeg
end tell
tell application "System Events"
open url_path
if not (exists url_path) then
beep
display dialog "not found"
else
display dialog (get album_title)
tell application "Finder"
activate
get document file
get name of document file
--name of file is "325.jpeg" referred to by url_path
--here I get persistent error messages
display dialog & name
set name to album_title
--set name of document file "325.jpeg" of folder "ALBUM COVERS POP" of folder "POPMUZIEK" of folder "Documents" of folder "apmwulfinghoff" of folder "Users" of startup disk to "First Ladies Of R&B.jpeg"
-- previous line is action as recorded in editor; all info is here available except "325.jpeg" separately
end tell
end if
--save document file
--close folder saving yes
end tell
================================
The real problem for me is to obtain the name of the document file; I can't figure out why I cannot succeed. -
Moving folder with photos and catalog ircat from one hard drive to another.
mac g4, 10.4.11, 1.5gb RAM
I need to free up space on my hardrive and want to move a folder which has photos and the lightroom catalogue .ircat in it as well as tiffs that have been worked on in potoshop, i want to keep them all togerth.
If i move that whole folder to another hardrive what do i have to do for lightroom to find it.. i have collections for this folder as well and don't want to lose them,
thanx.....You don't need to change the authorisation of your computer to keep your music on another drive connected to it. Have a look at this Apple guide it should help you moving your music folder: Moving your iTunes Music Folder
-
Create a folder with applescript?
how would i cretae a folder in a specific path with the
folder's name set to the current date and time?
/Volumes/path/to/folder/todaysdate_currenttime
thanks,
BabaGthanks neil.
one other question. once i've made this folder i'll want to use it.
it occurs to me that i might not be able to use the same code to
call the folder after it's been created since, while the date may
be the same, the time won't be.
how do i stored the new folder name as it's being created so that
i can call it later in the script?
thanks again,
BabaG -
How to get the file name from downloads folder with the applescript??
Hi All..
I am downloading an application to downloads folder, I need to install the same application after downloading programatically.
So how do I get the filename in runtime while downloading or after downloading from downloads folder with Applescript or Java?
Also my download URL link doesnot contain full name of the download file.
Pls suggest.Hi,
The best method is to use curl.
Other methods are not reliable, but can work, it depends on several factors (what the script does, what the user does).
Here is an example with the curl command:
set tUrl to "http://sourceforge.net/projects/vlc/files/2.0.4/macosx/vlc-2.0.4.dmg/download?ac cel_key=60%3A1350656196%3Ahttp%253A//www.videolan.org/vlc/download-macosx.html%3 A7233e4e9%245818d66f39b0576e1e9c4a0f3b46b1991180bfdd&click_id=976a88ee-19f7-11e2 -9a21-0200ac1d1d8e&source=accel"
set dFolder to path to downloads folder
tell application "Finder" to set newFolder to (make new folder at dFolder) as string
set f to quoted form of POSIX path of newFolder
do shell script "cd " & f & " && curl -L " & tUrl & " -o 'vlc.dmg'" -- download to file "vlc.dmg"
set downloadedFile to newFolder & "vlc.dmg" --<-- HFS path
--do something with the downloadedFile -
Download image from URL with applescript
I want to download an image from an website (and internal IP address) using applescript,
now I have found a script that works (Download jpeg image to folder with AppleScript from URL).
But, the web page requires a username and password...
When I convert the downloaded JPEG into a HTML by simply changing the extension, quick look displays the webpage's 401 unauthorized error page...
Does someone know how to make the applescript input the username and password?The answer depends on how the authentication is managed.
There are two common ways of implementing authentication in web browsers and knowing which one is used here is essential to scripting the request. One is also significantly harder than the other.
The first (easy) way is that the username and password can be submitted with the request. This is the original model and is easy to script - if you're using the curl model then it's just a matter of adding the -user switch to the command line:
-u, --user <user:password>
Specify the user name and password to use for server authentica-
tion. Overrides -n, --netrc and --netrc-optional.
This model is a little less secure, though, but might still be used on internal sites since it's easy to implement.
The other option is that the site uses cookies - you log in via a web form and the server gives your cookie which you then send with subsequent requests and are used to validate your access. This is a more secure, but is harder to implement because there is a multi-step process - login via the web form, capture the cookie, submit the cookie with the download request.
If you're not familiar with the different methods it can sometimes be hard to tell which one you need, and since it's an internal site there's no way anyone else can check... so you'll need to describe how you login to the site (or are prompted for authentication) before anyone can provide a direct answer. -
Automator and applescript to copy new files in a folder with same name as parent folder
I have an iMac with a pictures folder (Finder folder) containing several subfolders with pictures. As per now, all these subfolders are imported into an iPhoto library (and the structure of the Finder pictures folder is thus maintained: The iPhoto events are named the same as the Finder subfolder). I.e. I have not created any albums in iPhoto.
I have also set up a workflow, where new iPhone photos are automatically being synced to specified Finder folders within the iMac pictures folder. So what I want to do is to make a workflow to import potential new photos from week to week into the existing iPhoto structure. I know iPhoto has this Autoimport folder, so this one is unpacked and "mapped". So, this is what I´m hoping to do:
Automator (iCal - want to do this on a weekly basis):
- Get specified Finder items -- set to target folder = iMac pictures folder
- Get folder content (with subfolders)
- Filter Finder items
- Items from the last 7 days (which then would be any new files created last week)
- Applescript/shell script loop(?)
- Get folder name for each file´s (from previous step) parent folder
- Create new folder with same name as the file´s parent folder (if not already existing) under the iPhoto Autoimport folder
- Copy the given file into the folder from above
- Run iPhoto application (Automator task), which then should just auto import the new photos according to the Finder folder structure
Whith the workflow above, I aim to maintain the existing iPhoto structure, and just import new photos into the existing structure. Creating folder names under the Autoimport, similar as the existing Finder folder names / iPhoto events should make it possible to have the new files imported under the existing event, right?Anyone?
I have now switched to Aperture (from iPhoto) due to Aperture´s capability to handle Finder folder structure, and due to the possibility of having the pictures within Aperture as referenced files to the pictures within the Finder folders (i.e. possibility to delete pictures from both library and Finder folder at the same time).
So I have a superior Finder folder called "Album". Within "Album" I have several subfolders (sub albums) containing pictures. The "Album" folder with subfolders are imported into Aperture as "Projects and albums", and the pictures are uploaded within the Aperture structure as referenced files. So for now the Aperture structure is more or less a direct mirror of the Finder folder structure, whereas "Album" is the project.
And this is my current workflow in Automator, but I´m searching help with my Applescript:
- Get specified Finder items (target folder = the superior Finder folder "Album")
- Get Folder content
- Filter Finder items (to look for potential new files to import into Aperture)
- Kind is not folder
- Date created last X days
The output files from this task enters an Applescript
on run {input, parameters}
repeat with f in input (**Loop**)
tell application "Finder"
set fileName to name of (f)
set parentFolder to name of container of (f)
tell application "Aperture"
tell library 1
tell project "Album"
if (exists album parentFolder) then
** I then would like to check if fileName already exist within the existing album**
** If not existing, I would like to import file f into the existing album as a referenced file**
else if not (exists album parentFolder) then
make new album with properties {name:parentFolder}
** I then would like to import file f into the new album as a referenced file**
end if
end tell
end tell
end tell
end tell
end repeat
end run -
How to create a folder (with subfolders) with Applescript
Good afternoon,
Filemaker has the ability to ake use of AppleScript.
From within Filemaker I want to create a new folder (with the name of a FileMaker field) that holds 6 subfolders.
I am a complete noob where it comes to Applescript.
This is my script so far:
tell application "FileMaker Pro Advanced"
set folder_name to cell "FolderName" of current record
end tell
tell application "Finder"
activate
make new folder at folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:folder_name}
end tell
tell application "Finder"
activate
make new folder at folder {name:folder_name} of folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:"subfolder"}
end tell
My problem is: the creation of "Subfolder1"
What is my mistake there?
Help is much appreciated
Dick
Ps: I need to make 6 subfolders thereWhen you crate a new folder you can define various properties, but when refering to the folder just use the name, for example:
make new folder at folder folder_name of folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:"subfolder"}
Note that the result returned from making a new folder is a reference to that folder, so you can also do something like:
tell application "Finder"
set newFolder to (make new folder at folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:folder_name})
make new folder at newFolder with properties {name:"subfolder"}
end tell -
"Can't get folder 'a'" Error with Applescript
Here is my complete applescript application. I am supposed to select a series folder, and it goes into the folder and for each season folder does something inside, including grabbing the name of the season folder. But it keep throwing an error on the line set folderName to name of folder aFolder saying it can't get name of folder "a", but the only folders inside the folder I select are Season 1, Season 2, and Season 3. Additionally, looking at the replies part of the script editor it looks like it does "M" first with no errors, and they goes to "a". I have no idea where this is coming from so help me if you can. Disregard the weird formatting, copying everything from the script editor into here messed everything up. Thanks.
set seriesFolder to (choose folder with prompt "Select TV Series Folder") as text
tell application "Finder" to set tvName to "list of " & (name of folder seriesFolder as text) & " episodes"
openWebpage(tvName)
repeat with aFolder in seriesFolder
tell application "Finder"
set folderName to name of folder aFolder
set whichFile to every file of folder aFolder
sort whichFile by name
end tell
set sNumber to "0" & ((characters -1 thru -1 of folderName) as string)
set epNum to 1
repeat with aFile in whichFile
if epNum is less than 10 then
set ifZero to "0"
else
set ifZero to ""
end if
set textBox to "What is episode title for S" & (sNumber as string) & "E" & ifZero & epNum & "?"
tell application "Finder"
set filename to name of aFile
set nameEnding to ((characters -4 thru -1 of filename) as string)
display dialog textBox default answer ""
set text_returned to text returned of result
set name of aFile to "S" & (sNumber as string) & "E" & ifZero & (epNum as string) & " - " & text_returned & nameEnding
end tell
set epNum to epNum + 1
end repeat
end repeat
on openWebpage(input)
set seriesName to input
set needle to " "
set replacement to "+"
set searchName to search_replace(seriesName, needle, replacement)
set address to "http://www.en.wikipedia.org/w/index.php?search=" & searchName & "&title=Special%3ASearch&go=Go"
tell application "Safari" to open location address
end openWebpage
on search_replace(seriesName, needle, replacement)
set old_delimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to needle
set temp_list to every text item of seriesName
set AppleScript's text item delimiters to replacement
set return_value to temp_list as text
set AppleScript's text item delimiters to old_delimiters
return return_value
end search_replaceTry replacing the beginning of the script with:
set seriesFolder to (choose folder with prompt "Select TV Series Folder")
tell application "Finder"
set tvName to "list of " & (name of folder seriesFolder as text) & " episodes"
tell me to openWebpage(tvName)
repeat with aFolder in (get folders of seriesFolder)
set folderName to name of aFolder
(109908) -
Create folder with name Client150412n
Hi,
I'm new to ApplesScripting. I've found this script that I'd like to change:
--This script will make a new folder on the desktop with current date and dialog box
--format the date to 2010-11-19
tell (current date) to get day & (it's month as integer) & (it's year as integer)
set TheDateFormat to the result as text
-- asks for folder name with date as default answer
set TheFolderName to text returned of (display dialog "Name the folder" default answer TheDateFormat)
--make folder with date & user entered text
tell application "Finder"
make new folder with properties {name:TheFolderName}
end tell
The desired changes:
- Date format should be: 150412 + a letter (a, b, c) if the folder to be created already exists.
- Place the cursor at the start of name dialog, no selection active.
- The new folders should be created in /Users/Hans/Dropbox/Jobs/
Thanks,
Hans
Another question is related to execution of the script:
- How can I start the script easily with a shortcut key or a Dock icon?
- Is it possible to select client name from a plain text file containing client names in separate lines?
- Is it possible to have zip files automatically unzipped to subfolder names with the zip package name?
- Regarding the Dock icon I could even imagine that I drag a zip or other file from an email or the Desktop to the icon and that I only have to type the clients name to have the file moved to a new folder.save script as an application bundle. Drag app to dock.
Set short-cut key to app.
AppleScript Learn AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X, Third Edition the book
AppleScript Language Guide pdf download the pdf file -
Syncing a moved folder is not bringing back all the photos to Lightroom
I have moved and renamed a folder in the external harddrive. Syncing that moved folder in lightroom is not working in bringing back all the photos to Lightroom - Although all the photos exist in that folder as I have confirmed through windows explorer.
Another Option: If I choose "import photos to this folder option" in LR and browse to the source to that folder - the missing photos are shown as shaded back and the import button (bottom right corner) is not highlighted. Therefore I cannot select these missing photos and hence cannot import them to the folder.
PLEASE ADVISE!In the Folders Panel, the original folder should be listed with a "?" mark, because Lightroom can no longer find it. Right-click on it, select "Find Missing Folder", then browse to and select the renamed folder in its new location.
Note....these type of problems will continue to happen if you continue to rename and/or move folders or files outside of Lightroom. Do it using Lightroom and no such problems will arise.
Maybe you are looking for
-
Hi Is there any function module for F-04 transaction. Please help with answers.
-
Backup Dying HD in Target Mode?
I got the folder question mark icon. Disk Utility could not fix it and repeated the ominous "incorrect number of thread records" & "invalid volume file count". DiskWarrior made a good attempt, but with the thousands of "diskwarrior speed reduced to d
-
When will the new camera raw update come out for my nikon d7100
when will the new camera raw update come out for my nikon d7100
-
5.1 sound in After Effects?
How do I import and export 5.1 sound in After Effects? I have version 5.5. The file will then be converted to a dcp file /Mattias
-
Where to find JDBC version1.4 Driver for Informix (to use with OMWB)
Hi all, I want to migrate Informix 9.4 database to Oracle 10g. But, for this i need JDBC driver version 1.4 for Informix. On IBM site i can find only version 3.00 & 2.21 drivers. Please help me out. If possible can u send the link to [email protected