Applescript: Detection of File Extension does not work

Discussion in 'Mac Programming' started by surfcity, Apr 27, 2010.

  1. surfcity macrumors newbie

    Apr 27, 2010
    Hi Guys!

    I tried to write a Script to call with a System Service via a Shortcut to open a specific file, based on its filename extension. But the Applescript i wrote ends with an error message that the "name extension of" cannot be read.

    Does anyone of you guys have an idea what i am doing wrong?

    Thank you very much.

    Here's my script:

    global appName
    property image_extension_list : {"tif", "tiff", "gif", "png", "pict", "pct", "jpg", "jpeg"}
    property text_extension_list : {"html", "txt", "css", "php", "js"}
    on run {input, parameters}
    	tell application "Finder"
    		if (the name extension of the input is in the image_extension_list) then
    			set appName to "Adobe Photoshop CS3"
    		end if
    		if (the name extension of the input is in the text_extension_list) then
    			set appName to "TextMate"
    		end if
    	end tell
    	tell application appName
    		open input
    	end tell
    	return input
    end run
    This is intended to be a "Edit File" Script. For example: GIF-Files are normally linked with Preview-App. This is fine - but i want to call my Script to open it in Photoshop to edit it. :)
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    I think you're missing an (info for input) or an (input as alias). If 'input' isn't a file alias, it won't have a name extension property.
  3. surfcity thread starter macrumors newbie

    Apr 27, 2010
    Thank you! It's now doing what i wanted! :)
  4. Minimum91 macrumors newbie


    Apr 13, 2009
    Riga, Latvia
    Thank you OP for this script.
    Call me stupid, but I don't understand how to implement that 'info for input' or 'input as alias', could you please explain or better yet show an example? :confused:

Share This Page