InDesign: Reveal Links in Finder

indesignLoops through all the selected items, attempts to figure out whether any of them are linked images, and opens their containing folders, selecting all of ‘em.

Download Reveal-links-in-Finder.rb.zip.

The source code is bouncing from foot to foot in anticipatory glee, just after the jump.

#!/usr/bin/env ruby

# rb-appscript code by Ian Haigh : http://ianhaigh.com/
# Fri Dec  4 11:09:29 EST 2009

# loops through all the selected items, attempts to figure out whether any of
# them are linked images, and opens their containing folders, selecting all of
# 'em.

require 'rubygems'
require 'appscript'
include Appscript

def allItemLinks(objList)
	@myList = []

	objList.each do |obj|
		if [:PDF, :image].include?(obj.class_.get) then
			@myList << obj.item_link.file_path.get
		else
			obj.all_graphics.get.each do |img|
				@myList << img.item_link.file_path.get
			end
		end
	end
	@myList
end

@id = app('Adobe InDesign CS4.app')
@doc = @id.active_document

x = allItemLinks(@id.selection.get)
@finder = app('Finder.app')

# make an array with every image folder
image_folders = []
x.each { |path| image_folders << path.slice(/^.+:/) }

# reveal one file first
begin
	@finder.reveal(x[0])
rescue Exception => e
	puts "Couldn't reveal #{x[0]}"
end

# attempt to select all the files simultaneously
image_folders.uniq.each do |folder|
	begin
		@finder.open(folder)
		files_in_this_folder = x.select { |c| c.include?(folder) }
		@finder.set(:selection, :to => files_in_this_folder)
	rescue Exception => e
		puts "Couldn't reveal #{folder}:"
		puts e
	end

end

@finder.activate
This entry was posted in indesign. Bookmark the permalink. Trackbacks are closed, but you can post a comment.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • What’s this all about then?

    rb-appscript is a powerful way to automate your Mac. It's similar to Applescript but it's built in Ruby, which means you get to leverage that language's powerful syntax and libraries. Giving you more time to make toasted sandwiches. You want long-winded explanations? We got those.

    Please note that these scripts are by no means bulletproof, and are intended to provide examples of application scripting. I take no resposibility for any loss of data or mishaps; you download and run everything at your own risk. That said, I use all of these scripts in a production environment every day (well – more accurately, I use some of these scripts in a production environment most days).