Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to add icon previews and retain time stamps UNIX
sips is a fantastic command line tool which can add icons to image files so that they don't have to be auto-generated when you open a folder that has Show Icon Preview enabled. However, I never used it on my important images because it updates the files' time stamps as well. This means that if I generate icons today for images I took last year, those files would show up in the Finder as having been created today.

I finally couldn't take it any more, so I wrote a bash script to generate icons while preserving file times. It works on a variety of test files that I've used, including filenames with spaces, but since I'm no bash guru, it could contain some pitfalls.

[robg adds: This worked for me in testing on a few different image files; the icons were created without changing the files' time stamps.]
    •    
  • Currently 3.20 / 5
  You rated: 5 / 5 (5 votes cast)
 
[8,747 views]  

A script to add icon previews and retain time stamps | 7 comments | Create New Account
Click here to return to the 'A script to add icon previews and retain time stamps' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to add icon previews and retain time stamps
Authored by: billbarstad on Sep 25, '07 08:51:39AM

I'm new to shell scripts. How do I make it a bash script? How do I use it?



[ Reply to This | # ]
Add Icon to Image File
Authored by: mr. applescript on Sep 25, '07 09:15:26AM
To add or update an icon using SIPS or Image Events, just open and save the file using the with icon parameter. THe preview will be automatically generated:
set this_file to choose file of type "public.image" without invisibles
try
	tell application "Image Events"
		-- start the Image Events application
		launch
		-- open the image file
		set this_image to open this_file
		-- save the changes
		save this_image with icon
		-- purge the open image data
		close this_image
	end tell
on error error_message
	display dialog error_message
end try


[ Reply to This | # ]
Add Icon to Image File
Authored by: ploesslkh on Sep 25, '07 09:34:26AM

I tried this script but it did not retain the old creation date but changed it to todays!! Maybe I misunderstand how to use this apple script?



[ Reply to This | # ]
Add Icon to Image File
Authored by: JimMueller on Sep 25, '07 06:37:48PM
The whole idea of the original hint was to avoid changing the files' timestamps.

[ Reply to This | # ]
A script to add icon previews and retain time stamps
Authored by: lar3ry on Sep 25, '07 10:24:21AM
Add the following at line 3 (following the "##" line):
trap "rm -f /tmp/$UID.thumbnail-reference.tmp; exit" 0 1 2 3 15
This will remove the temporary file that this script creates when it exits.

A cleaner design would have this inlined into the code (remove the file before creating the reference stamp, and remove it once the file's time is reset) but "trap" is usually pretty good for quick and dirty cleanup.

[ Reply to This | # ]

A script to add icon previews and retain time stamps
Authored by: Nem on Sep 25, '07 11:43:25AM
Cudos - nice use of 'touch' to keep the file timestamp from getting updated. I've used the 'utime' function in the past to do this, but this is a nice way of doing it from the shell. Thanks - learned something today (and thus, its a good day!)

However, I don't like the temp file as a result of using touch (I see somebody else posted a 'trap' to at least clean up afterwards). Unfortunately, I don't see an easy way to convert the time output from something like 'stat' into the time format that 'touch' wants. If Mac's 'date' acted more like the GNU version, it would be easily doable. Actually, it would be fairly easy if you were to use perl instead of touch:

TSAVE=`perl -e '@s=(stat($ARGV[0]));print $s[9]' ${X}`
sips -i ${X}
perl -e 'utime($ARGV[0],$ARGV[0],$ARGV[1])' $TSAVE ${X}

---
Nem W. Schlecht
http://geekmuse.net/

[ Reply to This | # ]

A script to add icon previews and retain time stamps
Authored by: soundsgoodtome on Sep 25, '07 07:36:33PM

Also, if you have a copy of GraphicConverter, it will create icons/previews without modifying dates. Icon/preview creation is even available via contextual menu (control-click).



[ Reply to This | # ]