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

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

问题描述

我创建了一个脚本查找/文档中替换创建SQL INSERT语句,但到目前为止,我已经无法创造一个声明,让我使用保存的变量(日期),并延长保存结果(.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:用户:文件路径:麦金塔HD

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

任何帮助将是AP preciated。

Any help would be appreciated.

推荐答案

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天全站免登陆