tags:

views:

5408

answers:

4

Hi there!

I've also posted this on the macnn forums, but thought I may get a better response here.

I was hoping to find some help with using applescript (something I have never tried before, though I have a good knowledge of php etc)

I need to create an applescript that will copy specified files from one folder to a newly created folder.

These files need to be specified in the applescript.

so something like:

start

fileToBeMoved = "Desktop/Test Folder 1/test.doc"
newfoldername = "Test Folder 2"

make newfolder and name it 'newfoldername'
copy 'fileToBeMoved' to 'newfolder'

end

I'm so sorry for the rubbish description!

Hope someone can help!

Thanks!

+1  A: 

The trick with AppleScript is that moving files is done using aliases. Personally I find AppleScript exceptionally troublesome to write. (I could not and still can't get the code in Alex Reynolds answer to work whatsoever)

More realistically it might be easier to make a shell script instead which can be run from AppleScript using do shell script if you're using Automator or something similar.

#!/bin/sh

fileToBeMoved = "~/Desktop/Test Folder 1/test.doc"
newFolderName = "Test Folder 2"
mkdir $newFolderName
cp $fileToBeMoved $newFolderName
Chealion
+1  A: 

Generally:

tell application "Finder"
  make new folder at alias "Macintosh HD:Users:user:Desktop:" with properties {name:"Test Folder 2"}
  copy file "Macintosh HD:Users:user:Desktop:Test Folder 1:test.doc" to folder "Macintosh HD:Users:user:Desktop:Test Folder 2"
end tell

You can add variable names that represent POSIX files and paths.

Obviously the colon character (:) is a reserved character for folder- and filenames.

set desktopFolder to "Macintosh HD/Users/user/Desktop/"
set desktopFdrPosix to quoted form of POSIX path of desktopFolder
set newFolderName to "Test Folder 2"
set destinationFdrPosix to quoted form of desktopFdrPosix & POSIX file newFolderName
set sourceFilename to "Test Folder 1/test.doc"
set sourceFnPosix to quoted form of desktopFdrPosix & POSIX file sourceFilename

tell application "Finder"
  make new folder at alias desktopFdrPosix with properties {name:newFolderName}
  copy file sourceFnPosix to folder destinationFdrPosix
end tell

You may also want to add error checking if the destination folder already exists.

Alex Reynolds
A: 

set home_path to path to home folder as string set work_folder to alias (home_path & "AutomationAppleScript:ScreenShots:") tell application "Finder" copy every file of work_folder to folder "Archive" of home end tell

A: 

ugh... how to do this with a mounted server?

msbob