我正在尝试制作一项执行以下操作的Automator服务:
除了第三步之外我一切正常,这很重要,因为如果服务在同一文件夹中第二次运行,则已调整大小的文件将再次调整大小。为了解决这个问题,我想创建一个Applescript来过滤掉超过40秒/ 1分钟前创建的任何内容。
到目前为止,我有这个,并且它返回了一个错误:
on run {input, parameters}
set theFileDate to (creation date of input as string)
display dialog theFileDate
return input
end run
我正在尝试显示对话框,以便我可以验证代码是否正常工作并查看日期/时间的格式
答案 0 :(得分:2)
您必须使用Finder的脚本字典来访问创建日期属性。
on run {input, parameters}
tell application "Finder"
set theFileDate to (creation date of input as string)
end tell
display dialog theFileDate
return input
end run
答案 1 :(得分:0)
我处理了你的代码。我相信这更接近。
-- This script will (when completed) filter the list of Finder items in the input parameter
-- returning as an output only those files that meet the specified criteria.
on run {input, parameters}
-- if no items were selected, tell the user and cancel the workflow
if ((count of input) < 1) then
display alert "This workflow will do nothing because no items were selected in the Finder"
set CANCEL_WORKFLOW to -128
error CANCEL_WORKFLOW
end if
-- select the items to be output by this action
set output to {}
repeat with thisItem in input
-- display the thisItem's path name and creation date
display dialog (thisItem as text)
set theFileDate to (creation date of (get info for thisItem))
display dialog theFileDate as text
------ replace the next line of code with a compare of theFileDate to current date -----
set addThisItem to true
-----------------------------------------------------------------------------------------------
-- add items that meet the criteria to the output (which is a list)
if addThisItem then
set output to output & thisItem
end if
end repeat
-- return the output of this action to be the input of the next action
return output
end run
让我知道这是怎么回事。
答案 2 :(得分:0)
或者。
您只需在处理完文件后设置标签索引颜色。并筛选不是标记颜色的那些。
在此示例中,我使用标签索引紫色
过滤掉项目并且颜色处理后的项目为紫色,然后在第二次运行时被忽略。
答案 3 :(得分:0)
试试这个。请注意,您可以将“60”更改为“40”或任何其他所需的秒数。
on run {input, parameters}
set filterDate to (current date) - 60
set filteredFiles to {}
repeat with i from 1 to count of input
set thisFile to item i of input
if (class of thisFile) is text then set thisFile to thisFile as alias
set creationDate to (creation date of (get info for thisFile))
if creationDate is greater than or equal to filterDate then
set end of filteredFiles to (item i of input)
end if
end repeat
return filteredFiles
end run