我有一個文件夾充滿了圖像,我需要創建一個帶有applescript的所有圖像名稱的文本文件。有沒有什麼方法可以用Applescript讀取所有文件名中約有10k的文件名,然後將其輸出到文本文件中?任何幫助將是偉大的!謝謝閱讀。Mac用戶需要一些與applescript文件夾的幫助。 SFW
1
A
回答
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的輸出(列表目錄)命令寫入到文件中。您可以從一個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
中運行這個POSIX路徑的東西是把AppleScript的風格directory:paths:to your:files
到UNIX風格/directory/paths/to\ your/files
。
需要注意的是,實際上被運行shell腳本看起來像:
ls "/some/directory/path/">"/some/file/path.txt"
的報價都沒有停止空格或其他字符時髦從混亂的shell腳本。要停止在蘋果腳本中將引號讀爲引號,反斜槓被用來「逃避」它們。您還可以使用單引號,爲更可讀的代碼改爲:
做shell腳本( 「LS '」 & thePosixDrectory & 「 '>'」 & theposixResults & 「'」)作爲字符串
將出現在殼狀
ls '/some/directory/path/'>'/some/file/path.txt'
HTH
相關問題
- 1. 需要一些幫助與測試
- 2. 我需要一些幫助與PHP郵件(附加文件)
- 3. 需要一些幫助!
- 4. 需要一些PHP幫助
- 5. Django需要一些幫助
- 6. 需要一些幫助SC.SelectView
- 7. 需要一些幫助PVOID
- 8. 需要一些幫助#define
- 9. 需要幫助處理子文件夾
- 10. 需要一些幫助來使用NetBeans創建.jar文件
- 11. 需要一些序列化的幫助
- 12. 需要一些String.format的幫助
- 13. 需要一些基本的github幫助
- 14. 需要一些幫助,爲的DatePicker
- 15. 需要一些關於maven的幫助
- 16. 需要一些簡單的JavaScript幫助
- 17. 需要一些XElement查詢的幫助
- 18. 需要一些mod_rewrite規則的幫助
- 19. 需要域模型的一些幫助
- 20. 需要一些功能的幫助R
- 21. 需要幫助從文件
- 22. 在mac中使用F_NOCACHE需要幫助
- 23. MySQL錯誤需要一些幫助
- 24. 需要幫助,閱讀一些C#
- 25. 需要幫助編譯一些東西! (:
- 26. 我需要一些幫助理解OOP
- 27. 新手需要一些線程幫助
- 28. 需要一些幫助在C++ ifstream
- 29. 需要一些幫助SQL GROUPBY
- 30. 在CakePHP中需要一些幫助!
安全工作?我想這是... – 2009-06-25 23:21:02