and am unsure how to force a variable that is defined in the body of a script into the handler
ie
--=========== Use this set to control rotation globally===========
display dialog "What angle would you like for files?" & return & "use - for counter clockwise" default answer "-90"
set the_angle to the text returned of the result
--======== end global control ===============
on open these_items
repeat with i from 1 to the count of these_items
set this_item to (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 if (alias of the item_info is false) then
my process_item(this_item)
end if
end repeat
end open
-- 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 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 if (alias of the item_info is false) then
my process_item(this_item)
end if
end repeat
end process_folder
-- this sub-routine rotates the files
on process_item(this_item)
(*
--============ use these to control each file's angle individually=========
set the_info to info for this_item
display dialog "What angle would you like for file" & return & ((name of the_info) as text) & return & "use - for counter clockwise" default answer "-90"
set the_angle to the text returned of the result
--========== end individual angle control=============
*)
set the_file to this_item
tell application "Image Capture Scripting"
set this_image to open the_file
rotate this_image to angle (the_angle as number)
save this_image in the_file
close this_image
end tell
end process_item
–=========== Use this set to control rotation globally===========
display dialog “What angle would you like for files?” & return & “use - for counter clockwise” default answer “-90” setthe_angletothetext returnedoftheresult
globalthe_angle
–======== end global control ===============
onopenthese_items repeatwithifrom 1 tothecountofthese_items setthis_itemto (itemiofthese_items) settheitem_infotoinfo forthis_item iffolderoftheitem_infoistruethen
[color=green]process_folder/color elseif (aliasoftheitem_infoisfalse) then my [color=green]process_item/color endif endrepeat endopen
– this sub-routine processes folders on [color=green]process_folder/color setthese_itemstolist folderthis_folderwithoutinvisibles repeatwithifrom 1 tothecountofthese_items setthis_itemtoalias ((this_folderastext) & (itemiofthese_items)) settheitem_infotoinfo forthis_item iffolderoftheitem_infoistruethen
[color=green]process_folder/color elseif (aliasoftheitem_infoisfalse) then my [color=green]process_item/color endif endrepeat endprocess_folder
– this sub-routine rotates the files on [color=green]process_item/color globalthe_angle
(*[color=olive]
–============ use these to control each file’s angle individually=========
set the_info to info for this_item
display dialog “What angle would you like for file” & return & ((name of the_info) as text) & return & “use - for counter clockwise” default answer “-90”
set the_angle to the text returned of the result
– this sub-routine processes folders on [color=green]process_folder/color setthese_itemstolist folderthis_folderwithoutinvisibles repeatwithifrom 1 tothecountofthese_items setthis_itemtoalias ((this_folderastext) & (itemiofthese_items)) settheitem_infotoinfo forthis_item iffolderoftheitem_infoistruethen
[color=green]process_folder/color elseif (aliasoftheitem_infoisfalse) then my [color=green]process_item/color endif endrepeat endprocess_folder
– this sub-routine rotates the files on [color=green]process_item/color
(*[color=olive]
--============ use these to control each file's angle individually=========
set the_info to info for this_item
display dialog "What angle would you like for file" & return & ((name of the_info) as text) & return & "use - for counter clockwise" default answer "-90"
set the_angle to the text returned of the result
--========== end individual angle control=============
[/color]*)
[color=blue]set[/color] [color=green]the_file[/color] [color=blue]to[/color] [color=green]this_item[/color]
[color=blue]tell[/color] [color=blue]application[/color] "Image Capture Scripting"
[color=blue]set[/color] [color=green]this_image[/color] [color=blue]to[/color] [color=blue]open[/color] [color=green]the_file[/color]
[color=blue]rotate[/color] [color=green]this_image[/color] [color=blue]to angle[/color] ([color=red]the_angle[/color] [color=blue]as[/color] [color=blue]number[/color])
[color=blue]save[/color] [color=green]this_image[/color] [color=blue]in[/color] [color=green]the_file[/color]
[color=blue]close[/color] [color=green]this_image[/color]
[color=blue]end[/color] [color=blue]tell[/color]
global the_angle
on run
set thefolder to (choose folder) as alias
set these_items to list folder thefolder without invisibles
open thefolder & ":" & these_items
end run
on open these_items
-- =========== Use this set to control rotation globally===========
display dialog "What angle would you like for files?" & return & "use - for counter clockwise" default answer "-90"
set the_angle to the text returned of the result
-- ======== end global control ===============
repeat with i from 1 to the count of these_items
set this_item to (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 if (alias of the item_info is false) then
my process_item(this_item)
end if
end repeat
end open
-- 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 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 if (alias of the item_info is false) then
my process_item(this_item)
end if
end repeat
end process_folder
-- this sub-routine rotates the files
on process_item(this_item)
(*
--============ use these to control each file's angle individually=========
set the_info to info for this_item
display dialog "What angle would you like for file" & return & ((name of the_info) as text) & return & "use - for counter clockwise" default answer "-90"
set the_angle to the text returned of the result
--========== end individual angle control=============
*)
set the_file to this_item
tell application "Image Capture Scripting"
set this_image to open the_file
rotate this_image to angle (the_angle as number)
save this_image in the_file
close this_image
end tell
end process_item
I’m not sure what to make of the error at this point. In your run handler, what is this line supposed to do? Maybe it’s obvious and maybe I’m suffering another dense moment but I don’t get it.
open thefolder & ":" & these_items
On another note regarding the run handler, it isn’t necessary to add “as alias” to ‘set thefolder to (choose folder)’ since it will return an alias anyway.
I think this might do what you want it to do but it probably wouldn’t hurt to add some error checks.
global the_angle
on run
set thefolder to (choose folder)
tell application "Finder" to ¬
set these_items to items of thefolder as alias list
process_all(these_items)
end run
on open these_items
process_all(these_items)
end open
on process_all(items_)
-- =========== Use this set to control rotation globally===========
display dialog "What angle would you like for files?" & return & "use - for counter clockwise" default answer "-90"
set the_angle to the text returned of the result
-- ======== end global control ===============
repeat with i from 1 to the count of items_
set this_item to (item i of items_)
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) then
my process_item(this_item)
end if
end repeat
end process_all
-- this sub-routine processes folders
on process_folder(this_folder)
tell application "Finder" to ¬
set these_items to items of folder this_folder as alias list
repeat with i from 1 to the count of these_items
set this_item to 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 if (alias of the item_info is false) then
my process_item(this_item)
end if
end repeat
end process_folder
-- this sub-routine rotates the files
on process_item(this_item)
(*
--============ use these to control each file's angle individually=========
set the_info to info for this_item
display dialog "What angle would you like for file" & return & ((name of the_info) as text) & return & "use - for counter clockwise" default answer "-90"
set the_angle to the text returned of the result
--========== end individual angle control=============
*)
tell application "Image Capture Scripting"
set this_image to open this_item
rotate this_image to angle (the_angle as number)
save this_image in this_item
close this_image
end tell
end process_item