2009-05-23 39 views
9

指定したファイルをあるフォルダから新しく作成したフォルダにコピーするAppleScriptを作成する必要があります。これらのファイルのようなものようのAppleScriptエディタで指定する必要がAppleScriptファイルを新しいフォルダにコピー

:AppleScriptを持つ

start 

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

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

end 

答えて

4

トリックは、ファイルを移動すると、エイリアスを使用して行われるということです。

もっと現実的には、Automaterやそれに類するものを使っているのなら、AppleScriptからdo shell scriptを使って実行できるシェルスクリプトを作る方が簡単かもしれません。

一般
#!/bin/sh 

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

AppleScriptのものの上に、このメソッドを使用するために、その良いが、時にはあなたがアクセス許可の問題がある可能性があります原因と言うと、この方法を使用すると助けになります。 –

+0

これには以下のような欠点があります。コピーに時間がかかる場合、進行状況バーは表示されません。ユーザーは同じ理由でキャンセルすることもできません。シェルコマンドでこれらの操作をサポートすることは、単にFinderに任せるよりもずっと難しくなります。しかし、FinderのAppleScriptの弱点:ユーザーが置換「Finder」アプリを使用することを選択した場合、Applescriptの操作は失敗する可能性があります。 –

+1

Finderを使用するためのもう1つのプラス:目的地アイテムが存在する場合、ユーザーは交換するかどうかを尋ねられます。 –

9

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 

あなたはPOSIXファイルとパスを表す変数名を追加することができます。

明らかに、コロン(:)は、フォルダ名とファイル名の予約文字です。

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  

宛先フォルダがすでに存在する場合は、エラーチェックを追加することもできます。

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

これは、マウントされたネットワークボリュームにコピーするために動作します:それはあなたがあなたのAppleScriptで次のシェルスクリプトを実行することができます探している同期なら

mount volume "afp://compname.local/mountpoint" 
    tell application "Finder" 
     duplicate file "MyTextFile.txt" of folder "Documents" of home to disk "mountpoint" 
     eject "mountpoint" 
    end tell 
0

rsync -a /Users/username/folderToBeCopiedFrom /Volumes/folderToBeCopiedTo/

0
tell application "Finder" 
    make new folder at desktop with properties {name:"folder"} 
    duplicate POSIX file "/usr/share/doc/bash/bash.html" to result 
end tell 

POSIX file ((system attribute "HOME") & "/Documents" as text) 
tell application "Finder" to result 

tell application "Finder" to duplicate (get selection) to desktop replacing yes 

-- these are documented in the dictionary of System Events 
path to home folder 
POSIX path of (path to documents folder) 
path to library folder from user domain 
path to desktop folder as text 

-- getting files as alias list is faster 
tell application "Finder" 
    files of entire contents of (path to preferences folder) as alias list 
end tell 
0

私はChealionsシェルスクリプトソリューションを使用しました。スクリプトファイルを実行可能ファイルにすることを忘れないでください: sudo chmod u+x scriptFilename

また、変数割り当て内の記号=の間のスペースも削除してください。例えば、スペースで動作しません:newFolderName="Test Folder 2"

0

それを行うための簡単な方法は以下の通りであることは

set home_path to path to home folder as string 
set work_folder to alias (home_path & "AutomationAppleScript:ScreenShots:") 
tell application "Finder" 
    duplicate every file of work_folder to folder "Archive" of home 
end tell 
関連する問題