Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Open many images in Preview from Terminal UNIX
Here's a simple script that will allow you to open multiple files in Preview as a collection from the Terminal. This will allow you to browse multiple files in a single Preview window, very handy if you don't like Finder but dig the Terminal :)

Example of usage:
[guybrush@powerbook guybrush]$ cd photos
[guybrush@powerbook photos]$ preview *.jpg *.png
  1. Place the following code in the file preview:
    #!/bin/sh
    # A simple bash script that uses Applescript to
    # open multiple files in Preview. For example:
    # "preview hello.png world.gif *.jpg"
    
    if [ -z "$*" ]; then
      echo "Usage: $0 [FILE(S)]"
      exit
    fi
    
    PWD=${PWD//\//:}
    for file in $*;
    do
      if [ -n "$FILES" ]
      then
        FILES="$FILES, \"$PWD:$file\""
      else
        FILES="\"$PWD:$file\""
      fi
    done;
    osascript<<EOF
    tell application "Preview"
      activate
      open {$FILES}
    end tell
    EOF
    
  2. Make the script executable by typing chmod +x preview
  3. Copy the script to your bin directory for easy access: sudo cp preview /bin/preview
  4. Then execute it by typing: preview *.png
This script only works on files in the current working directory, due to the simplicity of the script.

[robg adds: You can, of course, just type open *.jpg in the Terminal to sort of do the same thing. The main difference is that this script opens one preview window with a drawer; the open method opens a bunch of individual windows. This script worked fine for me on 10.3.3 in tcsh...]
    •    
  • Currently 3.17 / 5
  You rated: 3 / 5 (6 votes cast)
 
[24,180 views]  

Open many images in Preview from Terminal | 7 comments | Create New Account
Click here to return to the 'Open many images in Preview from Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Open many images in Preview from Terminal
Authored by: jkreibich on May 18, '04 11:11:53AM
The command line utility "launch" will open multiple Preview documents in the same window (e.g. "launch *.jpg"). "launch" is a great replacement for "open", and can be found at http://web.sabi.net/nriley/software/launch-1.0.tar.gz.

[ Reply to This | # ]
Open many images in Preview from Terminal
Authored by: frankxiv on May 18, '04 12:14:14PM

You can also simply select all of the images you want to open and then drag them to the Preview icon in the dock. This will open one Preview document containing all of the images.

Later, Frank



[ Reply to This | # ]
Open many images in Preview from Terminal
Authored by: sjk on May 19, '04 01:20:17AM

When I did drag-dropped six PDF files on the Preview icon in the Dock it opened them in three windows, exactly the same as selecting them and using command-o or option-downarrow to open them.

Looks like multi-paged documents open in separate windows but I haven't confirmed that.



[ Reply to This | # ]
Open many images in Preview from Terminal
Authored by: webgodjj on May 18, '04 02:23:40PM

Is there a way to do this on a remote machine that I'm ssh'd into?



[ Reply to This | # ]
Open many images in Preview from Terminal
Authored by: Chiwo on May 19, '04 02:59:28AM

How is this different from "open -a Preview *.jpg"?



[ Reply to This | # ]
Open many images in Preview from Terminal
Authored by: guybrush on May 19, '04 05:26:59AM

Using that command will open all the pictures in seperate Preview windows (so for each picture a seperate Preview window), using the script will open all the pictures in 1 preview window and a drawer with thumbnails of the pictures on the right side.



[ Reply to This | # ]
Open many images in Preview from Terminal
Authored by: wmertens on May 19, '04 08:55:41AM
That is a nice script, but it's not hardened against spaces and giving subdirectories. Here's a new version with those two things fixed:

#!/bin/sh
# A simple bash script that uses Applescript to
# open multiple files in Preview. For example:
# "preview hello.png world.gif *.jpg"

if [ -z "$*" ]; then
  echo "Usage: $0 [FILE(S)]"
  exit
fi

PWD=${PWD//\//:}
for file in "$@";
do
  # Set all / to :
  file="${file//\//:}"
  if [ -n "$FILES" ]
  then
    FILES="$FILES, \"$PWD:$file\""
  else
    FILES="\"$PWD:$file\""
  fi
done;
osascript<<EOF
tell application "Preview"
  activate
  open {$FILES}
end tell
EOF


[ Reply to This | # ]