cagrimmett
cagrimmett

Reputation: 43

Open multiple images in single Preview window via AppleScript

I'm trying to open multiple image inside the same preview window. For example, if you drag multiple images into the sidebar of Preview, it will keep them neatly inside one window.

This code will open all of the images, but in separate windows:

-- Getting path to this file
tell application "Finder" to get folder of (path to me) as Unicode text
set currentLocation to result

-- Open image results in Preview
tell application "Preview"
    open currentLocation & "img:weekdays_bar.png"
    open currentLocation & "img:weekdays_pie.png"
    open currentLocation & "img:months_bar.png"
    open currentLocation & "img:seasons_bar.png"
    open currentLocation & "img:seasons_pie.png"
    open currentLocation & "img:am_pm_pie.png"
end tell

Can anyone point me in the right direction?

Upvotes: 1

Views: 728

Answers (1)

vadian
vadian

Reputation: 285082

Just put the pictures into a list and tell the Finder to open the files using Preview

tell application "Finder" to set currentLocation to container of (path to me) as text
set thePictures to {currentLocation & "img:weekdays_bar.png", currentLocation & "img:weekdays_pie.png", ¬
    currentLocation & "img:months_bar.png", currentLocation & "img:seasons_bar.png", ¬
    currentLocation & "img:seasons_pie.png", currentLocation & "img:am_pm_pie.png"}
tell application "Finder" to open thePictures using application file id "com.apple.preview"

Upvotes: 1

Related Questions