Applescript:我可以使用文件名和文件路径的变量保存文本文件吗? [英] Applescript: Am I able to save a text file using a variable for the filename and file path?

查看:35
本文介绍了Applescript:我可以使用文件名和文件路径的变量保存文本文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个脚本来在文档中查找/替换以创建 SQL 插入语句,但到目前为止我一直无法创建允许我使用保存的变量(日期)和扩展名保存结果的语句(.sql) 到不同的文件夹.

I have created a script to find/replace within the document to create an SQL insert statement, but so far I have been unable to create a statement that allows me to save the results using a saved variable (the date) and extension (.sql) to a different folder.

tell (current date) to set {_year, _month, _day} to {year, it's month, day}
set _day to text -2 thru -1 of ("00" & _day) -- add leading zeros if needed
set _month to text -2 thru -1 of ("00" & (_month as integer)) -- add leading zeros if needed
set _year to text -4 thru -1 of ("00" & (_year as integer))
set _date to _year & _month & _day

save text document 1 to file "Filepath:" & fileName without saving as stationery

这会导致以下错误:

错误BBEdit 出现错误:无法获取文件\"文件路径:\".编号 -1728 来自文件Macintosh HD:Users:Filepath:"

error "BBEdit got an error: Can’t get file \"Filepath:\"." number -1728 from file "Macintosh HD:Users:Filepath:"

任何帮助将不胜感激.

推荐答案

Zero 的 stringForDate 处理程序的略微优化版本

A slightly optimized version of Zero's stringForDate handler

 on stringForDate(aDate)
     if aDate is "" then set aDate to (the current date)
     if class of aDate is not date then return null
     set {year:dYear, month:dMonth, day:dDay} to aDate
     set dMonth to dMonth as integer
     if dMonth < 10 then set dMonth to "0" & dMonth
     if dDay < 10 then set dDay to "0" & dDay
     return ((dYear & "-" & dMonth & "-" & dDay) as string)
 end stringForDate

这篇关于Applescript:我可以使用文件名和文件路径的变量保存文本文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆