Mac Open all files from folder via Terminal

vloryan

macrumors member
Original poster
Jan 11, 2014
57
0
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
 

zeppenwolf

macrumors regular
Nov 17, 2009
129
3
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".
 

LPZ

macrumors 65816
Jul 11, 2006
1,221
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
Try

Code:
open -a /Applications/JPEGmini.app path/to/folder/xyz/*
 

vloryan

macrumors member
Original poster
Jan 11, 2014
57
0
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
 

LPZ

macrumors 65816
Jul 11, 2006
1,221
1
Thank you som much LPZ! Works. Almost :)
I'll run the with automator in the end.

Thanks so much for your help!
Vlo
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.
 

vloryan

macrumors member
Original poster
Jan 11, 2014
57
0
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?
 

LPZ

macrumors 65816
Jul 11, 2006
1,221
1
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?
After downloading the free JPEGmini Lite and playing around, I see no way of accomplishing (2) using Terminal.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
8,605
4,082
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.
 

vloryan

macrumors member
Original poster
Jan 11, 2014
57
0
ok, so there is still hope. unfortunately i gave no idea how to fo that either :(
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
8,605
4,082
ok, so there is still hope. unfortunately i gave no idea how to fo that either :(
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.
 

kryten2

macrumors 6502a
Mar 17, 2012
996
59
Belgium
ok, so there is still hope. unfortunately i gave no idea how to fo that either :(
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.
 

Attachments

Register on MacRumors! This sidebar will go away, and you'll see fewer ads.