Applescript 根据英国财政年度将文件分类到文件夹中
Applescript to sort files into folder based on British financial year
我正在寻找根据英国财政年度(从 4 月 6 日到 4 月 5 日运行)移动文件的方法。
文件命名模式为
2014-08-26_Asda_lunch.pdf
2016-03-20_Tesco_sationary.pdf
文件需要移动到指定的文件夹中,依此类推
FY 2014-15
FY 2015-16
只是想知道 applescript/ shell 脚本或自动操作是否有助于实现这一目标。与 hazel wud 的界面也更好
提前致谢
我试过修改脚本
我的首要目标是确定月份,然后尝试约会;
脚本的输出
文件 2019-07-26_Tesco_stationary -> 2020 财年(预计 2019-20 财年)
文件 2019-03-15_Sainsbury -> 2019 财年(预计 2018-19 财年)
请告知,任何在排序中添加日期的指针都会有所帮助
谢谢
set savedDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"-"}
tell application "Finder"
set filename to name of theFile
end tell
set expenseYear to (first text item of filename) as number
set expenseMonth to (second text item of filename) as number
set expenseDate to (third text item of filename) as number
-- Get the last two characters of the Year
set AppleScript's text item delimiters to savedDelimiters
set lastTwoCharactersOfYear to (characters 3 thru 4 of (expenseYear as text))
set RoundedExpYear to (lastTwoCharactersOfYear as text) as number
if expenseMonth ≥ 4 then
set LongString to expenseYear
set ShortString to RoundedExpYear + 1
else
set LongString to expenseYear - 1
set ShortString to RoundedExpYear
end if
set returnText to "FY" & " " & LongString & "-" & ShortString
有很多方法可以解析日期,但由于您的格式始终相同 (yyyy-mm-dd_xxxx),所以我使用了最简单的方法。在处理程序 GetFY returns 下方的脚本中,当您为参数提供文件名时,直接使用您要查找的格式“FY YYYY-YYYY”:
set Fname to "2014-03-05_xxxx" -- value to test
set myfolder to GetFy(Fname)
log "myfolder=" & myfolder
on GetFy(Fname) -- return FY-(FY+1) based on Fname as YYYY-MM-DD_xxxxxx
set myear to (text 1 thru 4 of Fname) as integer
set mmonth to (text 6 thru 7 of Fname) as integer
set mday to (text 9 thru 10 of Fname) as integer
if mmonth < 4 then set Fy to myear - 1
if mmonth = 4 then set Fy to myear - ((mday ≤ 5) as integer)
if mmonth > 4 then set Fy to myear
return "FY " & Fy & "-" & (Fy + 1)
end GetFy
我正在寻找根据英国财政年度(从 4 月 6 日到 4 月 5 日运行)移动文件的方法。 文件命名模式为
2014-08-26_Asda_lunch.pdf
2016-03-20_Tesco_sationary.pdf
文件需要移动到指定的文件夹中,依此类推
FY 2014-15
FY 2015-16
只是想知道 applescript/ shell 脚本或自动操作是否有助于实现这一目标。与 hazel wud 的界面也更好
提前致谢 我试过修改脚本
我的首要目标是确定月份,然后尝试约会; 脚本的输出 文件 2019-07-26_Tesco_stationary -> 2020 财年(预计 2019-20 财年) 文件 2019-03-15_Sainsbury -> 2019 财年(预计 2018-19 财年) 请告知,任何在排序中添加日期的指针都会有所帮助 谢谢
set savedDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"-"}
tell application "Finder"
set filename to name of theFile
end tell
set expenseYear to (first text item of filename) as number
set expenseMonth to (second text item of filename) as number
set expenseDate to (third text item of filename) as number
-- Get the last two characters of the Year
set AppleScript's text item delimiters to savedDelimiters
set lastTwoCharactersOfYear to (characters 3 thru 4 of (expenseYear as text))
set RoundedExpYear to (lastTwoCharactersOfYear as text) as number
if expenseMonth ≥ 4 then
set LongString to expenseYear
set ShortString to RoundedExpYear + 1
else
set LongString to expenseYear - 1
set ShortString to RoundedExpYear
end if
set returnText to "FY" & " " & LongString & "-" & ShortString
有很多方法可以解析日期,但由于您的格式始终相同 (yyyy-mm-dd_xxxx),所以我使用了最简单的方法。在处理程序 GetFY returns 下方的脚本中,当您为参数提供文件名时,直接使用您要查找的格式“FY YYYY-YYYY”:
set Fname to "2014-03-05_xxxx" -- value to test
set myfolder to GetFy(Fname)
log "myfolder=" & myfolder
on GetFy(Fname) -- return FY-(FY+1) based on Fname as YYYY-MM-DD_xxxxxx
set myear to (text 1 thru 4 of Fname) as integer
set mmonth to (text 6 thru 7 of Fname) as integer
set mday to (text 9 thru 10 of Fname) as integer
if mmonth < 4 then set Fy to myear - 1
if mmonth = 4 then set Fy to myear - ((mday ≤ 5) as integer)
if mmonth > 4 then set Fy to myear
return "FY " & Fy & "-" & (Fy + 1)
end GetFy