2009-06-25 4 views
1

私は画像がいっぱいのフォルダを持っており、すべての画像名のテキストファイルをappleescriptで作成する必要があります。 Applescriptには、約10kのファイル名をすべて読み込んでテキストファイルに出力する方法がありますか?どんな助けも素晴らしいだろう!読んでくれてありがとう。Macユーザーは、AppleScriptでいくつかのフォルダヘルプが必要です。 SFW

+4

のようなシェル?私はそれがだと思います... –

+0

私はそれが画像が何であるかによると思います.. – stib

答えて

5

ターミナルからやってみませんか?

LS> pix.txt

1

次のAppleScriptは、テキストファイルにフォルダ内のファイルの名前を書きます:

property theFolder : "File:Path:To:theFolder:" 

tell application "Finder" 

    -- Create text file on desktop to write filenames to 
    make new file at desktop with properties {name:"theFile.txt"} 
    set theFile to the result as alias 
    set openFile to open for access theFile with write permission 

    -- Read file names and write to text file 
    set theFiles to every item of folder theFolder 
    repeat with i in theFiles 
     set fileName to name of i 
     write fileName & " 
" to openFile starting at eof 
    end repeat 

    close access openFile 

end tell 
1

あなたがそれを開く前に、ファイルを作成する必要はありませんアクセス。あなただけでもできます

set theFile to (theFolder & "thefile.txt")as string 
set openFile to open for access theFile with write permission 

もちろん、ファイルが存在する場合は上書きされます。

set thefile to choose file name with prompt "name the output file" 

'ファイル名を選択する'は、ファイルを作成せずにパスを返し、ファイルが存在する場合に上書きするかどうかをユーザーに尋ねます。あなたが簡単な、よりエレガントな方法をしたい場合はもちろん

write fileName & return to openFile 

:あなたはまた、そうのようで破るラインを入れて「リターン」を使用することができます

、それはコードビットすっきりしますそれをすると、コマンドはあなたがする必要がある場所です。

ls>thefile.txt 

この例では、 '>'はls(listディレクトリ)コマンドの出力をファイルに書き込みます。あなたは、POSIXパスのものがUNIXスタイル/directory/paths/to\ your/filesにAppleScriptのスタイルdirectory:paths:to your:filesを有効にすることですAppleScriptの

set thePosixDrectory to posix path of file thedirectory of app "Finder" 
set theposixResults to posix path of file theresultfile of app "Finder" 
do shell script ("ls \"" & thePosixDrectory & "\">\"" & theposixResults & "\"")as string 

の中からこれを実行することができます。実際に実行しますシェルスクリプトは次のようになります

注:

ls "/some/directory/path/">"/some/file/path.txt" 

引用符は、シェルスクリプトを混乱からスペースや他のファンキーな文字をそこに停止しています。引用符がAppleScriptで引用符で読み込まれるのを止めるために、バックスラッシュがそれらを "エスケープ"するために使われました。に表示される文字列

として( "ls 'の" & thePosixDrectory & " '>'" & theposixResults & "'")

ないシェルスクリプト:あなたはまた、より読みやすいthuslyコードのために、単一引用符を使用することができます仕事のための安全な

ls '/some/directory/path/'>'/some/file/path.txt' 

HTH

関連する問題