Ask for text, pass to terminal, in Automator

Discussion in 'Mac Basics and Help' started by Cybbe, Feb 18, 2012.

  1. Cybbe macrumors 6502

    Joined:
    Sep 15, 2004
    #1
    I am trying to create a simple Automator service to quickly change metadata on photos. I would like to be able to select x amount of files, run the service, and get a popup that asks for the f-number I want to change to:

    At the moment this is set up to grab selected files in finder, and run the following terminal command:


    exiftool -FNumber="1.8" -overwrite_original_in_place "$@"

    [​IMG]

    (exiftool us an application used to edit metadata)

    This command works, but the FNumber is hardcoded to 1.8. I would like to be able to dynamically specify the f-number via the "Ask for text" command. However, I don't know how I can ask for text and use the selected files as inputs at the same time. Does anyone know how these variables should be defined, and how they can be passed to a shell script?
     
  2. kryten2, Apr 17, 2012
    Last edited: Apr 17, 2012

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Applescript

    Standalone script :

    Code:
    set these_files to (choose file with prompt "Pick the files to process:" with multiple selections allowed without invisibles)
    display dialog "Set your FNumber" default answer "\"1.8\"" buttons {"Cancel", "Ok"} default button 2
    copy the result as list to {text_returned, button_pressed}
    set the_FNumber to text_returned
    repeat with i from 1 to number of items in these_files
    	set this_item to item i of these_files
    	-- insert actions here
    	set this_item to quoted form of POSIX path of this_item
    	try
    		do shell script "exiftool -FNumber=" & the_FNumber & space & "-overwrite_original_in_place" & space & this_item
    	on error errMsg number errNumber
    		display alert errMsg message errNumber
    	end try
    end repeat
    Automator Run Applescript action :

    Code:
    on run {input, parameters}
    	(* Your script goes here *)
    	display dialog "Set your FNumber" default answer "\"1.8\"" buttons {"Cancel", "Ok"} default button 2
    	copy the result as list to {text_returned, button_pressed}
    	set the_FNumber to text_returned
    	repeat with i from 1 to number of items of input
    		set this_item to item i of input
    		-- insert actions here
    		set this_item to quoted form of POSIX path of this_item
    	try
    		do shell script "exiftool -FNumber=" & the_FNumber & space & "-overwrite_original_in_place" & space & this_item
    	on error errMsg number errNumber
    		display alert errMsg message errNumber
    	end try
    	end repeat
    	return input
    end run
     

Share This Page