Open all files from folder via Terminal

Discussion in 'Mac Programming' started by vloryan, Jan 11, 2014.

  1. vloryan macrumors member

    Joined:
    Jan 11, 2014
    #1
    Hi, i am very new to TERMINAL scripting. I would like to

    1. Open the app via TERMINAL (that works fine with
    Code:
    open /Applications/JPEGmini.app
    ...

    2. AND open all files from folder xyz in that app (i have no idea how to do this)

    I hope someone can help me here!

    Thanks! vlo
     
  2. zeppenwolf macrumors regular

    zeppenwolf

    Joined:
    Nov 17, 2009
    #2
    There are two parts to your number 2: getting a list of the files you want in "folder xyz", and opening them in your JPEGmini app.

    For getting a list, look at "man ls" in terminal.

    For opening them with your app, look at "man open".
     
  3. LPZ macrumors 65816

    Joined:
    Jul 11, 2006
    #3
    Try

    Code:
    open -a /Applications/JPEGmini.app path/to/folder/xyz/*
     
  4. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
    #4
    Thank you som much LPZ! Works. Almost :) As i cannot associate files (even JPEG) with JPEGmini i get an error when the app tries to open those files. So this is what i do manually:

    1. Open the JPEGmini app

    2. O > Choose Folder > the app NOW opens all these files.

    Any chance to have maybe two scripts?
    One that opens the app (already got that) and the other one that does the O job in that open app?

    I'll run the with automator in the end.

    Thanks so much for your help!
    Vlo
     
  5. LPZ macrumors 65816

    Joined:
    Jul 11, 2006
    #5
    Since you've mentioned Terminal, have you considered jpegoptim? It's available via MacPorts. Or you can get the latest source from

    http://www.kokkonen.net/tjko/projects.html

    and compile it yourself.

    Not sure about your level of expertise. Not sure how jpegoptim compares to JPEGmini as an optimizer. But since jpegoptim is a command line tool, you'd certainly be able to incorporate it into shell scripts.

    Just something to consider.
     
  6. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
    #6
    Thanks for the advice, but jpegoptim is by far not as good in reducing jpg file size as JPEGmini. So is there a chance to have to terminal line for (2) from above?
     
  7. LPZ macrumors 65816

    Joined:
    Jul 11, 2006
    #7
    After downloading the free JPEGmini Lite and playing around, I see no way of accomplishing (2) using Terminal.
     
  8. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
  9. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #9
    You could probably do it using an AppleScript.

    I haven't used AppleScript in over a year, and I never had much experience with it, but this sounds like the kind of thing that AppleScript does.
     
  10. vloryan thread starter macrumors member

    Joined:
    Jan 11, 2014
    #10
    ok, so there is still hope. unfortunately i gave no idea how to fo that either :(
     
  11. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #11
    Thank goodness for the internet, where a person who knows nothing can do a little searching in their favorite search engine (IE, Google or DuckDuckGo) and learn how to do simple things in a new language.

    You can look around and find lots of examples of opening applications in AppleScript and having it pick menu items.
     
  12. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #12
    Try this :

    Applescript :

    Code:
    activate application "JPEGmini Lite"
    
    tell application "System Events"
    	tell application process "JPEGmini Lite"
    		set frontmost to true
    		click menu item "Open…" of menu 1 of menu bar item "File" of menu bar 1
    	end tell
    end tell
    
    Shell script :

    Code:
    #!/bin/bash 
    
    /usr/bin/osascript <<-EOF
    
    activate application "JPEGmini Lite"
    
    tell application "System Events"
    	tell application process "JPEGmini Lite"
    	set frontmost to true
    	click menu item "Open…" of menu 1 of menu bar item "File" of menu bar 1
    	end tell
    end tell
    
    EOF
    
    Note : Change "JPEGmini Lite" to whatever you're using e.g. how it's named in the Applications folder. You need to give access to the UI in the Privacy --> Accessibility section for Applescript Editor and/or Terminal. If you're on Mavericks it will ask you to do so on the first run of the scripts.
     

    Attached Files:

Share This Page