Img2icns (non scriptable) script need help!

Hey Guys,

I discovered applescripting about 1 weeks ago and this is the first time that I’m confronted to unscriptable application: Img2icns…
here is the idea of my script :


set theFiles to choose file with prompt "?"
set pathToImg2icns to (path to applications folder as Unicode text) & "Img2icns.app"

tell application "Finder"
	open theFiles using application file pathToImg2icns
	tell application "System Events"
		tell front process to click UI element "Folder" of window "Img2icns"
		
	end tell
	
end tell

but i got an error "could’tn retrieve window “img2icns” of process 1…

Any idea?

thx

If that can help you help me, i have also tried this getting the infos from Accessibility Inspector:

set theFiles to choose file with prompt "Tiff File?"
set pathToImg2icns to (path to applications folder as Unicode text) & "Img2icns.app"

tell application "Finder"
	open theFiles using application file pathToImg2icns
	activate application "Img2icns"
	tell application "System Events"
		tell process "Img2icns"
			click button "Folder" of window "standard window"
		end tell
	end tell
end tell


try this…

-- this uses the application Img2icns: http://www.img2icnsapp.com/
-- you select a file and choose how you want it saved
--you can create an icns image, a folder with the image, a favicon, or an iphone icon
-- the file is automatically saved to the desktop with the same base name as the selected file

set pathToImg2icns to (path to applications folder as text) & "Img2icns.app"
set outputFormatList to {"ICNS file", "Folder", "Favicon", "iPhone"}

-- choose the file to use
set theFile to choose file with prompt "Choose the file to use for its image!" without invisibles

-- choose the output format
choose from list outputFormatList with prompt "Choose the Output Format" default items (item 1 of outputFormatList) OK button name "Select" cancel button name "Quit"
tell result
	if it is false then error number -128 -- cancel button pressed
	set choice to first item
end tell

-- calculate the button number fro the choice
if choice is (item 1 of outputFormatList) then
	set theButton to 5
else if choice is (item 2 of outputFormatList) then
	set theButton to 8
else if choice is (item 3 of outputFormatList) then
	set theButton to 6
else
	set theButton to 7
end if

-- open the file
-- for some reason I have to do this twice to get it to work
repeat 2 times
	tell application "Finder" to open theFile using application file pathToImg2icns
	delay 0.2
end repeat

-- save it and quit the program
tell application "Img2icns" to activate
tell application "System Events"
	tell process "Img2icns"
		click button theButton of window "Img2icns" -- choose the appropriate button
		delay 0.2
		keystroke "d" using command down -- make sure the desktop folder is where the file is saved
		click button "Choose" of window 1
	end tell
end tell
tell application "Img2icns" to quit

just another option – this is shorter and without the choices that Hank added…

set theFile to choose file with prompt "Select an image file." without invisibles
set theButton to 8
activate application "Img2icns"
tell application "Img2icns" to open theFile
tell application "System Events" to tell process "Img2icns"
	click button theButton of window "Img2icns"
end tell

I killed the lines in Hank’s scripts that I got errors on.

-- this uses the application Img2icns: http://www.img2icnsapp.com/
-- you select a file and choose how you want it saved
--you can create an icns image, a folder with the image, a favicon, or an iphone icon
-- the file is automatically saved to the desktop with the same base name as the selected file

set pathToImg2icns to (path to applications folder as text) & "Img2icns.app"
set outputFormatList to {"ICNS file", "Folder", "Favicon", "iPhone"}

-- choose the file to use
set theFile to choose file with prompt "Choose the file to use for its image!" without invisibles

-- choose the output format
choose from list outputFormatList with prompt "Choose the Output Format" default items (item 1 of outputFormatList) OK button name "Select" cancel button name "Quit"
tell result
	if it is false then error number -128 -- cancel button pressed
	set choice to first item
end tell

-- calculate the button number fro the choice
if choice is (item 1 of outputFormatList) then
	set theButton to 5
else if choice is (item 2 of outputFormatList) then
	set theButton to 8
else if choice is (item 3 of outputFormatList) then
	set theButton to 6
else
	set theButton to 7
end if

-- >>>>>>>>>> I got an error with this...
(* 
-- open the file
-- for some reason I have to do this twice to get it to work
repeat 2 times
   tell application "Finder" to open theFile using application file pathToImg2icns
   delay 0.2
end repeat
*)

-- Just this one line works for me...
tell application "Img2icns" to open theFile

-- save it and quit the program
tell application "Img2icns" to activate
tell application "System Events"
	tell process "Img2icns"
		click button theButton of window "Img2icns" -- choose the appropriate button
		delay 0.2
		keystroke "d" using {command down} -- make sure the desktop folder is where the file is saved
		-- click button "Choose" of window 1 -- <<<<<<< I got an error with this
	end tell
end tell
tell application "Img2icns" to quit

Tom

Operating System: Mac OS X (10.5)

THAAANNNNKKKKSSS

here is the result of my script

What you need:
-Photoshop CS (any versions)
-Img2icns to be installed in application folder (http://www.img2icnsapp.com/)
-Move the Cover.psd (http://massadian75.free.fr/macscripter/Cover.psd) to Desktop

here is how it works

  1. Launch the Script
  2. He will ask you for your images folder:
    NO MATTER IMAGES SIZE OR RATIO, THE APPLICATION DEALS WITH THAT!!!
  3. He does a lot of stuff in photoshop and set files to become icons
    DO NOT TOUCH YOUR MOUSE AND KEYBOARD OR THE ACTION WILL BE STOPED
set Image_Folder to choose folder with prompt "Select the file contaigning your posters"
tell application "Finder"
	set Image_Count to count of files in folder Image_Folder
	set Desk to path to desktop folder from user domain
	set a to file "Cover.psd" of Desk as text
end tell
tell application "Adobe Photoshop CS4"
	activate
	open file a
	set Cover to current document
	tell Cover
		set gtemp to layer set "Base" of Cover
		
	end tell
end tell
repeat with i from 1 to Image_Count
	tell application "Finder"
		set This_Image to item i of Image_Folder as alias
	end tell
	tell application "Adobe Photoshop CS4"
		tell Cover
			set Image_Set to duplicate layer set "Base" to beginning
		end tell
		open This_Image
		set Image_Doc to the current document
		tell Image_Doc
			resize image height 480 as pixels
			set Image_Name to name as text
			set In_without to (characters 1 thru -5 of Image_Name) as string
			-- Trim down your file name here
			set This_Layer to layer 1 of Image_Doc
			duplicate This_Layer to end of first layer set of Cover
			close without saving
		end tell
		tell Cover
			set name of first layer set to In_without
			set name of first layer of first layer set to In_without & " Case"
			set name of last layer of first layer set to In_without & " Cover"
			(select region {{91, 26}, {91, 491}, {421, 491}, {421, 26}})
			invert selection
			clear
			deselect
			
		end tell
	end tell
end repeat
tell application "Adobe Photoshop CS4"
	tell Cover
		delete last layer set
		make art layer at end of Cover
	end tell
	tell application "Finder"
		set targetFolder to make new folder at desktop ¬
			with properties {name:"Tiff"}
	end tell
	
	tell application "Adobe Photoshop CS4"
		repeat with u from 1 to Image_Count
			tell Cover
				set u to first layer set of Cover
				set LayerName to name of u
			end tell
			make new document with properties ¬
				{mode:RGB, height:512, width:512, resolution:300, initial fill:transparent}
			set current document to last document
			set Temp to current document
			set current document to Cover
			duplicate u to Temp
			set current document to Temp
			tell Temp
				
				save as TIFF with options {class:TIFF save options, image compression:none, save alpha channels:true, transparency:true} in (targetFolder as text) & LayerName & ".tiff"
				tell result
					close
				end tell
				tell Cover
					delete first layer set
					--set current document to document 1 
					--duplicate u to beginning of Temp
					
				end tell
			end tell
		end repeat
		
		close Cover without saving
		
	end tell
end tell
--ICONYFY RESULT
set pathToImg2icns to (path to applications folder as text) & "Img2icns.app" --APPLICATION A UTILISER

set theButton to 8 --FOLDER

repeat with y from 1 to Image_Count
	repeat 3 times
		tell application "Finder" to open item y of targetFolder using application file pathToImg2icns
		delay 1
	end repeat
	
	tell application "Img2icns" to activate
	tell application "System Events"
		tell process "Img2icns"
			delay 1
			click button theButton of window "Img2icns" -- choose the appropriate button
			delay 1
		end tell
	end tell
	tell application "Img2icns" to quit
	
end repeat


 

Thanks again for the help