Hallo! I’ve already posted in /Automator, but thought someone might help me here instead.
I want to make a service that gets multiple files in Finder and creates a folder from them, but names it by default with the first item’s creation date. This would be useful for photos.
How can I define “input” as the first item of the selection?
What am I missing here?
service receives files or folders in Finder get folder contents run AppleScript
tell application "Finder"
set theFileDate to (creation date of input as string)
make new folder at window 1 with properties {name:text returned of (display dialog "Choose a name" default answer theFileDate)}
move selection to the result
end tell
on run {input, parameters}
if input is not {} then
set firstItem to item 1 of input
tell application "Finder"
set theFileDate to (creation date of firstItem) as string
set newFileName to text returned of (display dialog "Choose a name" default answer theFileDate)
make new folder at container of firstItem with properties {name:newFileName}
move input to the result
end tell
end if
return input
end run
I figured out how to remove the time and format the date the right way:
on run {input, parameters}
set firstItem to item 1 of input
tell application "Finder"
set theCreationRaw to (creation date) of firstItem -- formatting begins
set y to text -4 thru -1 of ("0000" & (year of theCreationRaw))
set m to text -2 thru -1 of ("00" & ((month of theCreationRaw) as integer))
set d to text -2 thru -1 of ("00" & (day of theCreationRaw))
set theFileDate to y & "-" & m & "-" & d -- formatting ends
set newFileName to text returned of (display dialog "Choose a name" default answer theFileDate)
make new folder at container of firstItem with properties {name:newFileName}
move input to the result
end tell
return input
end run