bonjour a tous alors voila je vous expose mon problème vu que je débute sur applescript et sur mac en général. j'ai un script qui me renomme mes fichiers avec la date de création, comment le modifier pour que ce script s'execute automatiquement sans avoir besoin de le lancer?
voila le script:
voila le script:
on run
-- get the list of selected ID's in front window
set selectedItems to GetSelection()
-- show about
AboutScript()
-- process each item
set theCount to 0
tell application "ExtendScript Toolkit 2"
repeat with theItem in selectedItems
-- get exif date & original name
set newName to ""
set theName to the name of theItem
set thePath to the «class pPat» of theItem
--display dialog thePath
set theDate to the «class pE0e» of theItem
--try
-- form new name
set theYear to ((year of theDate) as string)
set theMonth to my getPaddedString(my getMonthNumber(theDate))
set theDay to my getPaddedString(day of theDate)
set theHours to my getPaddedString((time of theDate) div hours)
set theMins to my getPaddedString(((time of theDate) mod hours) div minutes)
set theSecs to my getPaddedString((time of theDate) mod minutes)
set newName to theYear & "-" & theMonth & "-" & theDay & "-" & theHours & "-" & theMins & "-" & theSecs
-- if the old name has an extension, append it to new name
set nc to the number of characters in theName
if character (nc - 3) of theName = "." then
set thefileextension to (get text (nc - 3) through nc of theName)
end if
-- rename
if theName ≠ (newName & thefileextension) then
--does a file already exist with this name?
tell application "Finder"
set filefolder to (folder of alias thePath)
set filenumber to ""
set counter to 1
set myloop to true
repeat until myloop is false
if exists file (newName & filenumber & thefileextension) of filefolder then
if filenumber = "" then
set filenumber to "_" & counter
else
set filenumber to "_" & counter + 1
set counter to counter + 1
end if
else
set myloop to false
end if
end repeat
end tell
set the name of theItem to (newName & filenumber & thefileextension)
if the name of theItem = (newName & filenumber & thefileextension) then set theCount to theCount + 1
end if
--end try
end repeat
end tell
ShowResult(theCount)
end run
-- get the selected media items in an array ---------------------------------------------
on GetSelection()
set selectedItems to {}
tell application "ExtendScript Toolkit 2"
if window 1 exists then set selectedItems to the selection of window 1
end tell
if number of items in selectedItems is 0 then
display dialog ¬
"You need to select at least one media item in the front catalog in order to use this script." buttons {"OK"} default button ¬
"OK" with icon 1 giving up after 10
error number -128
end if
return selectedItems
end GetSelection
-- about this script ---------------------------------------------
on AboutScript()
display dialog ¬
"This script will rename original files of all selected items using valid values in the \"Capture Date\" field." buttons {"Cancel", "Rename"} default button 2 with icon 1
set theAnswer to the button returned of the result
return theAnswer
end AboutScript
-- show result ---------------------------------------------
on ShowResult(theCount)
if theCount = 0 then
set theMsg to "Script completed." & return & "No items were renamed."
else if theCount = 1 then
set theMsg to "Script completed." & return & "1 item was renamed."
else
set theMsg to "Script completed." & return & theCount & " items were renamed."
end if
display dialog theMsg buttons {"OK"} default button "OK" with icon 1 giving up after 10
end ShowResult
on getPaddedString(aNumber)
if aNumber < 10 then
return "0" & (aNumber as string)
else
return (aNumber as string)
end if
end getPaddedString
on getMonthNumber(aDate)
if month of aDate is January then
return 1
else if month of aDate is February then
return 2
else if month of aDate is March then
return 3
else if month of aDate is April then
return 4
else if month of aDate is May then
return 5
else if month of aDate is June then
return 6
else if month of aDate is July then
return 7
else if month of aDate is August then
return 8
else if month of aDate is September then
return 9
else if month of aDate is October then
return 10
else if month of aDate is November then
return 11
else if month of aDate is December then
return 12
end if
end getMonthNumber