Reputation: 25
I'm trying to make an Automator service that does the following:
I have everything working except step three, which is important because if the service is run a second time in the same folder the already resized files will be resized a second time. In order to work around this I want to create an Applescript that filters out anything that was create more than 40 second/1 minute ago.
So far I have this, and it's returning an error:
on run {input, parameters}
set theFileDate to (creation date of input as string)
display dialog theFileDate
return input
end run
I'm trying to display dialog so that I can verify the code is working and see the format for the date/time
Upvotes: 1
Views: 4299
Reputation: 19032
Try this. Note that you can change "60" to "40" or any other amount of seconds needed.
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
Upvotes: 0
Reputation: 6932
Or.
You simply set the label index colour when the files have been processed. And filter for ones that are not the labeled colour.
Here in this example I filter out items with the label index Purple
And colour processed items purple which are then ignored on the second run.
Upvotes: 0
Reputation: 474
I worked on your code. I believe that this is closer.
-- 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
Let me know how this goes.
-- Kaydell
[email protected]
http://learnbymac.com
Upvotes: 0
Reputation: 1154
You have to use Finder's scripting dictionary to access the creation date property.
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
Upvotes: 2