ごんれのラボ

iOS、Android、Adobe系ソフトの自動化スクリプトのことを書き連ねています。

【改変】ドロップしたらフルパスを書き出す

ドロップされたもののフルパスを取得して、デスクトップにフルパスを書き込んだテキストファイルを作成するAppleScript。

スクリプトで画像貼る時にフルパスが必要なので、作ってみました。

本当は一個投げれば解決するんだけど、さみしいので複数ドロップに対応させてみた。

 

<仕様>

●ドロップされたもののフルパスを取得してデスクトップにフルパスを書き込んだテキストファイルを作成する

●デスクトップに作成されたファイルは上書きされていくので注意

 他の用途で「fullpath.txt」というファイルをデスクトップに置いておいても問答無用で上書きされる

 ダイアログを出してユーザーに警告する仕様に変更

●書き出されたファイルはUTF-16っぽいのでそれが開けるエディタ(Jeditやmi)などが必要

 エンコーディングがよくわからないから消したw

●UTF-8でテキストファイルを書き出すように変更

 

一度公開してからTwitterで@monokanoさん、@mori_tacsiさん、@iketch_xさん、@happyscriptさん、@seuzoのアドバイスを受けて改変してるので、使用する人は再度落とし直してください(^^;

仕事終わってTwitter見てみたらリプライがご指摘の山でちょっとびびりましたw

「あー、私の適当ブログでも見てくれてる人はいるんだなー」と思えてありがたかったです。

 

 

on open dropFolder

set fullPathGroup to ""

repeat with doropedFile in dropFolder

set pathStr to doropedFile as Unicode text

if fullPathGroup is "" then

set fullPathGroup to pathStr

else

set fullPathGroup to fullPathGroup & (ASCII character (10)) & pathStr

end if

end repeat

tell application "Finder"

if exists file ((desktop as text) & "fullpath.txt") then --デスクトップにfullpath.txtが存在したら

display dialog "すでにfullpath.txtが存在します。上書きしますか?" buttons {"キャンセル", "OK"} default button "OK"

if (button returned of result) is "OK" as text then --OKなら

set aTextFile to open for access ((desktop as text) & "fullpath.txt") with write permission

set eof aTextFile to 1

try

write fullPathGroup to aTextFile as «class utf8» --UTF-8で書き出し

on error aErrorText

display dialog aErrorText

end try

close access aTextFile

end if

else --しなかったら作る

set aTextFile to open for access ((desktop as text) & "fullpath.txt") with write permission

set eof aTextFile to 1

try

write fullPathGroup to aTextFile as «class utf8» --UTF-8で書き出し

on error aErrorText

display dialog aErrorText

end try

close access aTextFile

end if

end tell

activate

display dialog "フルパスをテキストに書き出しました" buttons {"OK"} default button "OK"

end open