Simple file conversion question

I have a script that takes a video snapshot from within iChat, which saves to the the desktop in TIFF. I wish to take the TIFF file (Video Snapshot 1) and convert it to JPG and move to a folder on my desktop called “Attachments”

Can someone help me? I’m new to scripting“sorry if this is too easy.

Steve

For a framework, Apple provides an example as a Folder Action Script to duplicate and Image as JPEG, that you’ll find by running this, which will open a Finder window, select the file and open it in your Script Editor for you. Ask questions about that if need be.


tell application "Finder"
	activate
	reveal alias ((path to scripts folder from local domain as text) & "Folder Action Scripts:Image - Duplicate as JPEG.scpt")
	open selection
end tell

It would be much more straight-forward if you could direct the TIFF file to a separate folder to which the Folder Action could be attached, rather than having the file appear “naked” on the desktop, but I don’t use iChat and you don’t give us the script you use to place it there, so don’t know how you might set it.

Here’s my script to activate the menu command in iChat

activate application “iChat”
tell application “System Events” to keystroke “s” using {command down, option down}

iChat saves a TIFF file on the desktop. This is the file I want to convert to JPG and move to a folder on the Desktop. I don’t think you can modify the menu function.

On the “General” pane of the iChat preferences at the bottom is a drop-down menu: “Save received files to:”. The first choice is ‘Desktop’ but you can choose “Other” and select a previously created file wherever you want it to be.

Tried that. Snapshots only get saved to the desktop.

I don’t like the idea of attaching a Folder Action to the desktop - that’s a busy place. Better is to use an ‘on idle’ script that watches the desktop for a file with extension “tif” or “tiff” and whose name contains “Video”, convert it and save it to Attachments. This script will do that every 30 seconds. You save it as a stay-open application. When you run it, it will appear in your Dock. Change return 30 to whatever you want, but don’t beat the system to death. It does not delete the original - that’s left on the desktop.


property dest : ((path to desktop folder as text) & "Attachments:")
on idle
	tell application "Finder"
		ignoring case
			set TF to (files of desktop whose name extension is "TIFF" or name extension is "TIF") as alias list
		end ignoring
		repeat with aTF in TF
			if name of aTF contains "Video" then
				set theImage to contents of aTF
				tell application "Image Events"
					set I to open theImage
					save I as JPEG in dest
					close I
				end tell
			end if
		end repeat
	end tell
	return 30 -- seconds
end idle

Thanks, I’ll give it a try tomorrow at work. What I’m doing is to use my Powermate to trigger an Applescript to:

  1. take snapshot within iChat of the video preview window which saves it as a TIFF file on the desktop
  2. convert the TIFF file to a JPEG
  3. move it into the Attachments folder.
  4. it has to do it once after each trigger.

I was thinking, only if the script could select for a portion of the filename - and you came up with it.

I’ll try it with the idle and return parts removed, and it should work to follow the snapshot script:

activate application “iChat”
tell application “System Events” to keystroke “s” using {command down, option down}

Wish me luck!

Steve

You have to do something about the original file left behind or it’ll trigger another copy. I suggest that you use this version, which will leave the original in the trash. Note too that because ‘as alias list’ doesn’t work for a single file and ‘as alias as list’ doesn’t work for multiples (it’s an AppleScript bug), I’ve added a try block for collecting the name extensions incase there is more than one video…tiff file.


property dest : ((path to desktop folder as text) & "Attachments:")
-- Add your trigger stuff here, and perhaps a short delay might be needed while iChat creates the tiff.
tell application "Finder"
	ignoring case
		try
			set TF to (files of desktop whose name extension is "TIFF" or name extension is "TIF") as alias as list
		on error
			set TF to (files of desktop whose name extension is "TIFF" or name extension is "TIF") as alias list
		end try
	end ignoring
	repeat with aTF in TF
		if name of aTF contains "Video" then
			set theImage to contents of aTF
			tell application "Image Events"
				set I to open theImage
				save I as JPEG in dest
				close I
			end tell
			delete aTF -- if you prefer you can create another folder ("originals" perhaps) and move them there.
		end if
	end repeat
end tell

I tried it without the idle and return commands and I got this in the event log:

tell application “Finder”
get every file of desktop whose name extension = “TIFF” or name extension = “TIF”
{alias “Steve PB:Users:sypark:Desktop:Video.barrett.tif”}
“Can’t make alias "Steve PB:Users:sypark:Desktop:Video.barrett.tif" into type «class alst».”

I have a file called Video.barrett.tf on my desktop. It got humg up at the alias. So when I got rid of “as alias list”, I get this:
tell application “Finder”
get every file of desktop whose name extension = “TIFF” or name extension = “TIF”
{document file “Video.barrett.tif” of desktop folder}
get name of document file “Video.barrett.tif” of desktop
“Video.barrett.tif”
open document file “Video.barrett.tif” of desktop
“The variable I is not defined.”

I’ve just modified it to deal with that (which I discovered just as you tried it). See the post before your last.

Thanks, Adam. I really appreciate all your help.

Steve

More than welcome. I’d never tried “Image Events” before, so it was educational for me too (and a PITA to discover how you had to script it. It took a long time {too long} for me to discover that you had to open the file in IA before doing anything with it).

Adam