LoginSignup
2

More than 5 years have passed since last update.

USBメモリー内の選択したファイルを指定したフォルダにコピーするAppleScript

Posted at

やりたいこと

 特定のUSBメモリー内に含まれるファイルを、
1. 指定したフォルダにコピーしてから、
2. ゴミ箱に移して、
3. ゴミ箱を空にして、
4. アンマウントする
 までがルーティーンになっていたので、AppleScriptで自動化したい!

スクリプト

tell application "Finder"
    --1. 選択ファイルを指定フォルダにコピー
    move selection to choose folder with prompt "コピー先のフォルダを選択して下さい"
    --2. 選択ファイルをゴミ箱に移動
    delete selection
    --3. ゴミ箱を空にする
    display alert "Empty trash?" buttons {"cancel", "OK"}
    set isEmpty to button returned of result
    if isEmpty = "OK" then
        empty
    end if
    --4. USBメモリーをアンマウント
    eject "USBmemory"
end tell

メモ

  1. USBメモリーから外付HDDへのコピーを想定しているので、moveだけで勝手にコピーされる
  2. ゴミ箱を空にするのは、万が一を考えてクッションを置いた
  3. USBメモリーのアンマウントは、特定のUSBメモリーしか使わないので、名前で指定

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2