Using applescript to open "any" images in an specified application?

I want to use applescript as part of a workflow in Automoator.
Automator already takes care of the renaming and resizing of my pics.
Then I want applescript to take each pic that I throw at it and apply it to an image optimizer application I have.
I've looked all over gooel and I can' find anything.
Everyscript I see has a specific file name or folder.
I want applescipt to take a file with any name and launch "ImageOptim" and open the file with ImageOptim.
This app is a drag and drop app, just drop your pictures on the window or on the icon and it'll optimize your pics on the spot. It doesn't create a new file, the file itself is changed.
And that's it.
I had this but it doens't work
set this_file to choose file without invisibles
try
          tell application "Finder"
  activate
                    open application file "ImageOptim.app" of folder "Applications" of startup disk
                    set this_image to open this_file
          end tell
end try
Thanks for the help.

Red's already shown you one solution, but your script has multiple errors and it's worth clarifying them
set this_file to choose file without invisibles
OK, nothing wrong with this line
          tell application "Finder"
  activate
There's no need to activate the Finder to perform this task. The Finder's quite happy to run in the background.
                    open application file "ImageOptim.app" of folder "Applications" of startup disk
This opens the application.
                    set this_image to open this_file
This would open this_file - except that this command is completely independent and disconnected from the previous command - in other words you're just telling the Finder to open the file, it doesn't care about what other commands you might have asked it to run previously.
The solution is to tell the Finder to open the file using the specific application you want.
Another option may be to eschew the Finder altogether, and just tell the app to open the file:
set this_file to choose file without invisibles
tell application "ImageOptim" to open this_file

Similar Messages

  • Leopard Can't open any Image HELP!!

    This is very weird, I've been working fine all these past days since I installed Leopard, but suddenly I am not able to open any image file (giff, tiff, jpeg, even Acrobat files) with my preview image or photoshop, it looks like the file is open, I mean, IT IS OPEN but I CANT SEE ANYTHING, when I click the window toolbar I see that the file is there, but I cant see anything, same thing happend with Photoshop, I see all the layers of the file, I see even the file in the navigator, but I cant see the file itself !!! help, thanks

    Sorry that didn't work. Here are some other suggestions.
    How big is your Hard Drive, and how much room is left on it? Apple suggests you leave at least 10-15% free at all times, or else weirdness may ensue.
    What kind of Install of Leopard did you do? If you did the Upgrade, weirdness may ensue. Back everything up and Archive and Install (preserving all users) or, better, Erase and Install. You can use Time Machine for the backup and reinstall from it. I've done it, and it works.
    Also, did you download the 10.5.1 update? If so, did you do it from Software Update (39MB) or Apple Downloads(110MB)? If you didn't install it, go to Apple Downloads and use that one for best results.
    Hope some of these help.
    Message was edited by: Susan M

  • Preview can't open any images

    Hi all,
    Suddenly Preview doesn't work with any images on my computer (stil works fine with PDF). The Preview window is always like this when I try to open any images:
    I had tried to remove all the preference files related to Preview under ~/Library/Preferences/, also used Disk Uitility to repair disk permissions but no luck.
    Can somebody help me? Thanks

    Have you tried starting in Safe Mode and see if the problem still occurs?
    Restart holding the "shift" key.
    (Expect it to take longer to start this way because it runs a directory check first.)
    If this works look in System Preferences > Users & Groups > Login items and disable any third party login items. Also look in /Library/Startup Items. Nothing is put in that folder by default, so anything in there is yours.

  • I have a LR 3.6  64 bit that refuses to open any images today

    I have a LR 3.6  64 bit that refuses to open any images today.  Computer restore point created  and used , Norton cleaned still not joy any ideas guys?

    Rose, the problem is that you've somehow managed to ask Lightroom create a catalog folder with the name of an existing photo file, which as you have seen causes problems in LR3 (the bug was fixed for later releases). The only reliable fix is to reset the Lightroom preferences file (so that it forgets about that invalid catalog, so stops trying to open it). C.frans has already given you a link to tell you how to reset the preferences, but if you need more detailed instructions you can find them here:
    http://www.lightroomforums.net/showthread.php?14226-Resetting-(or-Trashing-)-the-Lightroom -Preferences-file

  • Open any image

    Hi,
    I found some code to open JPGs, but I need to be able to open any image file (or at least both JPG and GIF)... Could anyone please give me some help with this?
    FileInputStream fis = new FileInputStream(chooser.getSelectedFile());
    JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(fis);
    img = decoder.decodeAsBufferedImage();
    fis.close();
    Thanks!!!

    A quick and easy way to load images of multiple types (png, jpg, gif etc) is to use the following code:
    Image image;
    image = Toolkit.getDefaultToolkit().getImage(new URL("file:someimage.png"));
    In order for this to work, the image that you want to load has to be in the same directory as the class file that you are running. If the image is somewhere else, such as on the Internet or somewhere else on your harddrive, then simply modify the new URL() portion of the code to reflect the location of your image. If you need to make sure that the image has completely loaded before using it, such as if you want to get its width and height through code, then you would also attach a MediaTracker object to it, like the following:
    Image image;
    MediaTracker tracker;
    image = Toolkit.getDefaultToolkit().getImage(new URL("file:someimage.png"));
    tracker = new MediaTracker(this); //The "this" should be something such as the canvas you're using
    tracker.addImage(image, 0);
    tracker.waitForAll(); //Wait for image to finish loading
    Hope that helps.

  • Can't open any image in CC after crash

    After a pc crash I am not any more able to open any image in Photoshop cc,  I can select an image, press load but nothing happens.
    I did an uninstall and reinstall, deleted all folders in AppData\Roaming\Adobe\Adobe Photoshop CC, deactivated OpenCL, still no luck.
    Any help is highly appreciated. Thanks.

    Try resetting preferences.  Start PS and immediately hold down ctrl alt shift keys.  If fast enough you will get a reset window.  File not affected by reinstall.

  • Display drivers crashing and restarting after opening any image in Photoshop CS6. After that Photoshop CS6 doesn't respond.

    I have just purchased Acer Aspire R7 (2nd Genre). I have installed Photoshop CS6 as trial. Now when I open any image or drag any image in Photoshop I get this error in the taskbar "Display driver stopped responding and has recovered". After that Photoshop doesnt respont and I have to force close it from task manager.
    Can anyone guide me how to solve this issue?

    Well, what more do you need to know? Update your graphics drivers and configure them suitably.
    Mylenium

  • My x3 phone can't open any image file

    i updated my phone yestrday and after that, my phone cannot open any image files....it says 'no image to display'......now whats wrong with my phone????

    /t5/Xseries/Can-Someone-Help-me/td-p/712783
    Previous Phones: 6600, 7610, 6230, 6230i, 1100, 1112, N70, N73, N95, N95 8GB, 5800XM, 5230, C5, iPhone 3GS, SE Xperia X10, N900, N8, SE Xperia Arc
    Current Phones: Nokia N9, iPhone 4

  • PSE does not open any image nor it is possible to open a new file

    Hello,
    having installed Photoshop Elements 13 for the first time on my Windows 7 Ultimate (64 Bit) computer it is a big disappointment.
    I cannot open any image. It does not matter whether it is on a network share or local disk.
    Have no deinstalled the program and reinstalled. But the behaviour does not change at all.
    In the organizer I can select an image but when I want to transfer it the editor nothing happens.
    It is also not possible to create a new empty image.
    Anybody else having this behaviour?
    - Holger -

    Hi  Ing-HoBa ,
    Are you able to launch Photoshop Elements 13 Editor?
    If not please follow these steps;
    Go to following location:
    for Win
    C:\Program Files (x86)\Common Files\Adobe
    C:\Users\username\AppData\Local\Adobe
    for MAC
    Finder> Go > Go to Folder
    \Library\Applicaiton Support\Adobe
    ~\Library\Applicaiton Support\Adobe
    Locate folder OOBE and rename it OOBE.old
    Download and install
    Adobe - Adobe Application Manager : For Windows : Adobe Application Manager
    Adobe - Adobe Application Manager : For Macintosh : Adobe Application Manager
    After the installation
    Try to Open Adobe Application Manager / Creative Cloud App.
    Log in that with Adobe ID and Password.
    If it does not work first try couple of times more.
    Let me know if this resolves the issue.
    Reagrds
    Sandeep

  • I recently upgraded to Mac OS X.  I hadn't try to access anything in iWorks 09 since the upgrade, until now.  I get an error message when trying to open any of the iWorks 09 applications.  What's the fix for this?

    I recently upgraded to Mac OS X.  I haven't tried to access anything in iWorks 09 since the upgrade, until now.  I get an error message when trying to open any of the iWorks 09 applications.  What's the fix for this?

    Follow Sonicray's advice and when you post try to give as much info about your Mac, your OS, etc... Fill out your Profile info.

  • How do I stop camera raw adjusting contrast and brightness automatically when I open any image

    Every time I open in image in camera raw or Photoshop it is applying an automatic contrast and brightness setting. I have tried resetting to defaults with cntrl shft del but it doesn't make a difference. It also when I just flick through thumbnails on bridge. The pics look almost like they have a cartoon like filter on them!!any ideas on how I get it all back to normal it's been great in the past . I use cs3

    Short answer, learn how to use the tool...
    As for the "auto" adjustments, are you sure that's what's happening or are the images changing based on the differences between what the camera preview and the Camera Raw preview look like? If you have indeed somehow turned on the "Auto" adjustment and saved that out as a Camera Raw default, you can go into the Camera Raw flyout menu and choose the option to Reset Camera Raw Defaults. If however you are talking about the inherent differences between the way your camera renders raw and the way Camera Raw renders it, that's an entirely different discussion...
    As for your other question, try rephrasing it as it doesn't mean a thing to me so I have no idea how to answer...

  • Suddenly can't open any image files in PSE11

    Last used PSE11 a couple of months ago. The organizer and Elements worked normally. Today I attempted to open some JPEG files in Elements on my PC and nothing shows up in the photo bin or the editing window. Tried with a varieity of JPEGs and non of them open in PSE11. Used the Organizer with no problems but Elements simply won't load any image file of any type.
    Opened a couple of my images in a photo editor that came with my PC and Windows Paint with no problems. What the heck is going on here?

    When you say nothing is showing up, do you mean it is as if you didn’t use File / Open, or is it more that there is something but it is gray or white or black without any image detail?  If the latter, perhaps something like a video driver update or system-level change has made things incompatible with how PSE11 tries to display images.
    Have you rebooted?
    Have you reset your preferences?  You can do this by holding down Ctrl-Shift-Alt at the same time while PSE11 is starting up (or at least while the editor is starting up) and you’ll get a message about deleting the preferences file or not before you see the splash screen.   Various other key combinations will ask for an additional plug-ins folder or a different scratch disk location.  If you are going to delete your preferences file you might want to review the settings, first, in case there is something important you need to reconfigure once the preferences have been reset.

  • Using applescript to open launchpad

    Hello all,
    I just bought a new iMac yesterday, and I love the multitouch features of my new magic mouse, but I had wanted to be able to add a few more so that I could use similar functions to those which I use on my iPad. I discovered the app Magicprefs, and it works great, but one thing I wanted to do was make it so that a two finger swipe up opens Launchpad, and a two finger swipe down closes it. From what I can tell, Magicprefs makes it so that a two finger swipe up will open and close Launchpad, and same with a two finger swipe down. I was trying to use applescript to make it so that a swipe up will only open it and a swipe down will only close it, not do both. The problem is that while I am familiar with basic programming I am not familiar with the exact language used in applescript and also it looks like launchpad is not simply opened and then quit so these basic commands are not working. Could anyone give me the basic code I can use to tell Magicprefs to open it with a swipe up and to close it with a swipe down? Or if this is even possible? Thanks for any help!

    You can't make a keyboard shortcut to run a specific application from OSX, although there are third party applications such as Quicksilver that can do things like that. You can use an AppleScript to activate an existing menu item, for example:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    tell application "Finder" to activate
    tell application "System Events" to tell application process "Finder"
    keystroke "A" using {shift down, command down}
    end tell</pre>
    Other alternatives to keyboard shortcuts are to use the Scripts Menu or add an application to the Finder's toolbar. The Script Editor does not need to be active to use scripts.

  • Photoshop Elements 7 Editor crashes upon opening any image

    I have been trying for 2 days to get my Photoshop to work.
    I've used PSE7 for years, no issues. Suddenly yesterday, every time I try to open an image in the full editor, I get the "Photoshop has stopped working... check online for a solution or close the program" message.
    I tried uninstalling and reinstalling PSE7, rebooting, as well as plenty of other fixes I found on here. Nothing has worked.
    I'm on Windows Vista 64 bit.
    I tried to call Adobe customer support ALL DAY, since 9am. Between hours of hold time, being told I have to leave a call back number that never gets called back, and getting hung up on by the rudest customer service rep in the history of the world, I am at the end of my rope.
    I'm a professional photographer and graphic designer, and I've now lost 2 full days of work time and cannot get a single answer on forums or help on the phone from Adobe. I'm seriously losing it.
    Can someone please help me figure out what happened to the program I was perfectly and completely happy with for years so I can get some work done?
    Thanks,
    Maggie

    This FAQ has several troubleshooting suggestions:
    http://www.johnrellis.com/psedbtool/photoshop-elements-faq.htm#_Troubleshooting_Editor_cra shes
    Ken

  • Using applescript to open a folder with a keyboard shortcut

    hello -
    i have a rather simple question (probably). is there a way using applescript to create a keyboard command to open a folder? i.e. command shift a opens the applications folder and command shift u opens utilities. can i use applescript to designate a keyboard command to open a folder i have created? also, the script editor does not have to be open for me to utilize scripts, correct?
    thanks for your patience with a newbie.

    You can't make a keyboard shortcut to run a specific application from OSX, although there are third party applications such as Quicksilver that can do things like that. You can use an AppleScript to activate an existing menu item, for example:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    tell application "Finder" to activate
    tell application "System Events" to tell application process "Finder"
    keystroke "A" using {shift down, command down}
    end tell</pre>
    Other alternatives to keyboard shortcuts are to use the Scripts Menu or add an application to the Finder's toolbar. The Script Editor does not need to be active to use scripts.

Maybe you are looking for