这将BBEdit
's保存text document 1
为fileName
(带有扩展名.sql
)
到desktop folder
:
使用do shell script
命令创建日期戳的版本:
set fileName to (do shell script "/bin/date +%Y-%m-%d") & ".sql"
set filePath to ((path to desktop folder) as text) & fileName
tell application "BBEdit"
if exists text document 1 then
save text document 1 to file filePath
else
beep
end if
end tell
使用 AppleScriptdate
创建日期戳的版本:
set fileName to my stringForDate("") & ".sql"
set filePath to ((path to desktop folder) as text) & fileName
tell application "BBEdit"
if exists text document 1 then
save text document 1 to file filePath
else
beep
end if
end tell
on stringForDate(aDate)
if aDate is "" then set aDate to (the current date)
try
set dYear to year of (aDate) as number
set dMonth to month of (aDate) as number
set dDay to day of (aDate) as number
if dMonth < 10 then set dMonth to "0" & dMonth
if dDay < 10 then set dDay to "0" & dDay
return ((dYear & "-" & dMonth & "-" & dDay) as string)
on error
return "-ERROR"
end try
end stringForDate
如果要检查文件是否已经存在,请在filePath
设置后插入:
tell application "Finder"
if exists file filePath then
beep
display dialog "Overwrite existing file?" buttons {"Overwrite", "Cancel"} default button 2
if the button returned of the result is "Cancel" then
return
end if
end if
end tell
加法
这里有一点帮助,把你想要的路径放入剪贴板。在脚本中执行以下代码并选择要存储文件的文件夹:
set rootFolder to (choose folder with prompt "Pick a folder…") as string
set the clipboard to rootFolder
现在该路径已在剪贴板中,可以粘贴了。
示例:DiskName:Users:shortusername:Desktop:rootFolder:
现在更换
set filePath to ((path to desktop folder) as text) & fileName
和
set filePath to "DiskName:Users:shortusername:Desktop:rootFolder:" & fileName
当然,“DiskName:Users:shortusername:Desktop:rootFolder:”是剪贴板中文本的示例。