Maybe it already exists? This will avoid starting from scratch?
My problem is very simple. But I can not solve it only with the Finder search function. (I’ve try with Raw Query, but not nought powerful).
I have thousands of pictures over several months (a Very Long TimeLapse):
I give a source folder (with sub folders !)
I give a start time in the morning
I give an end time in the evening
I give an interval X (eg every 6 minutes)
I give a destination folder
Then the script starts from the very first picture (from the creation date from EXIF data), and for each day, only includes photos taken between the start hour and end hour. And in this interval, it selects a photo X minutes after the last. If there are none: after X minutes + 1. If there are none: X minutes + 2… until finding a photo.
Thus, it ignores photos too close (less than X minutes between each photo).
Finally, each selected photo is virtually copied to another folder: not a true copy. Not an alias. Just a “hard link”. Thus, it does not take place.
Any suggestion ? Any existing script(s) wich I could base my script on ?
Thanks I’m not enough good in AS to make the script from scratch. That’s why I said “Maybe it already exists? This will avoid starting from scratch?”. But It was not clear. Sorry
I’ve read your link, but can’t found a start of solution. Because about EXIF, I have to search simply for this entry : kMDItemDateAdded (http://photophindings.blogspot.fr/2012/02/searching-exif-data-with-mac-os-x.html)
There alot of AS solutions/samples and other useful informations.
Here a simple AS for recursive read images files.
-- QuickTime supported image formats
property rasterTypeList : {"JPEG", "8BPS", "8BPB", "TIFF", "PNGf"}
property rasterExtensionList : {"jpg", "jpeg", "psd", "psb", "tif", "tiff", "png"}
property rasterTypeIDsList : {"public.png", "public.jpeg", "com.adobe.photoshop-image", "dyn.ah62d4rv4ge81a65c", "public.tiff"}
-- Vector images files formats
property vectorTypeList : {"EPSP", "PDF"}
property vectorExtensionList : {"ai", "eps", "pdf"}
property vectorTypeIDsList : {"com.adobe.illustrator.ai-image", "com.adobe.encapsulated-postscript", "com.adobe.pdf"}
property vectorFilesPath : {} -- vector files paths
property rasterFilesPath : {} -- raster files paths
-- This droplet processes files dropped onto the applet
on open droppeditems
my setFilesList(droppeditems)
set vectorFilesCount to the count of the vectorFilesPath
set rasterFilesCount to the count of the rasterFilesPath
if vectorFilesCount < 1 and rasterFilesCount < 1 then
-- select nothing
return
end if
-- do some stuff here
end open
on setFilesList(droppeditems)
repeat with i from 1 to the count of droppeditems
set this_item to item i of droppeditems
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else
try
set this_extension to the name extension of item_info
on error
set this_extension to ""
end try
try
set this_filetype to the file type of item_info
on error
set this_filetype to ""
end try
try
set this_typeID to the type identifier of item_info
on error
set this_typeID to ""
end try
if (folder of the itemInfo is false) and (alias of the itemInfo is false) and ((thisFiletype is in the vectorTypeList) or (thisExtension is in the vectorExtensionList) or (thisTypeID is in vectorTypeIDsList)) then
copy this_item to end of vectorFilesPath
else if (folder of the itemInfo is false) and (alias of the itemInfo is false) and ((thisFiletype is in the rasterTypeList) or (thisExtension is in the rasterExtensionList) or (thisTypeID is in rasterTypeIDsList)) then
copy this_item to end of rasterFilesPath
end if
end if
end repeat
end setFilesList
-- this sub-routine processes folders
on process_folder(this_folder)
set these_items to list folder this_folder without invisibles
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as Unicode text) & (item i of these_items))
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else
try
set this_extension to the name extension of item_info
on error
set this_extension to ""
end try
try
set this_filetype to the file type of item_info
on error
set this_filetype to ""
end try
try
set this_typeID to the type identifier of item_info
on error
set this_typeID to ""
end try
if (folder of the itemInfo is false) and (alias of the itemInfo is false) and ((thisFiletype is in the vectorTypeList) or (thisExtension is in the vectorExtensionList) or (thisTypeID is in vectorTypeIDsList)) then
copy this_item to end of vectorFilesPath
else if (folder of the itemInfo is false) and (alias of the itemInfo is false) and ((thisFiletype is in the rasterTypeList) or (thisExtension is in the rasterExtensionList) or (thisTypeID is in rasterTypeIDsList)) then
copy this_item to end of rasterFilesPath
end if
end if
end repeat
end process_folder
So, I’ve found part of solution : I’ve found a way to rename all my photos with EXIF date like “YYYMMDD-hhmmss.jpg”
Then, I’ll put all this renamed photos in one folder.
Then, in lightroom, I’ll remove all “night” pictures.
Thus, I only need a much more simple script to analyse just the name of each file : I need to extract “mm”. If “mm” of a photo is inferior to “mm”+X of the last photo, I add a “red” tag to this wrong photo. The I test the next photo… etc…
Finally, I’ll sort my photo by tags in finder, to select only non-red-tagged pictures.
Is it more simple to find a script near what I need ?
Well, finally I got into it. I have a stupid bug I think! He told me that my variable “hmancien” is not defined! And yet I well defined in the routine “faisLalisteDesElements” through which one has to pass before you use this variable in the routine “traiteFichier”. I do not understand.
That works, yes, but it covers up the actual cause of the error. Which will cause you more trouble in the future.
Variables declared in a handler are only known to that handler.
You declare hmancien in handler faisLalisteDesElements, but do not use it there.
It is only used in handler traiteFichier, so it should be declared there.
Delete set hmancien to “0” as integer, and add a line to the top of the 2nd handler: set hmancien to 0.
And delete the property.
Yes, hmancien seems to be only used in handler traiteFichier. But each time I use traiteFichier, I d’ont want to initialize hmancien to 0. hmancien is used to memorize the time of the last file before the actual file.
Since this code, I’ve worked more. Here my new version : I’ve also discovered that property keep values even after close the app !!! Now I use global. It works now. What do you think ?
Don’t! Don’t use globals unless there’s a good reason.
you have to keep track of their value at all times
you will use a variable locally, having forgotten that it’s a global as well, and your script will misbehave
as soon as you start reusing code similar problems will multiply
and so on
And, as I did say earlier, making a variable global may cover up the actual problem that you thought to solve.
The correct way is to pass variables to handlers:
Change this
on traiteFichier(lElement)
to this
on traiteFichier(lElement, DossierHardLinks)
and you will have passed the value of DossierHardLinks to the handler - no need for the global.
A few other things:
you don’t need the run statements
text returned is already text, no need for as string
as string is “old style”, it should be as text
I recommend reading the stuff in the Unscripted section, and getting a book.
property yourVariableOne : missing value
property yourVariableTwo : 0 as integer
property yourVariableThree : {}
on run
set my yourVariableOne to missing value
set my yourVariableTwo to 0 as integer
set my yourVariableThree to {}
-- some stuff goes here
end run