• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Preview.app scriptable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Preview.app scriptable


  • Subject: Re: Preview.app scriptable
  • From: DeNigris Sean <email@hidden>
  • Date: Sun, 17 Jan 2010 11:56:35 -0500

> As I reported before, the 'first window' didn't move at all when scripted. By accident then I adressed window 2, and voilĂ , it did what it should (using 'size' and 'position' as you suggested, 'bounds' are not working).

Sometimes Preview decides to use 1 as the front window, and sometimes it uses 2.  You have to do some kind of test to avoid the phantom window when it's present like "find the first window that has a name." I haven't done enough research to know for sure, but it may be related to the type of file that's opened first (seems like jpg=1, pdf=2).

Here's some Ruby code that shows the situation.  I hope it helps.  You can pretty easily translate it into applescript:

describe "#front_window" do
	context "when preview decides 1 is the index of the front window" do
		it "should get front window" do
			#Open file in app from command line per http://lifehacker.com/302197/useful-command-line-tricks-for-mac-users
			`open -a Preview #{jpg_test_file_path}`
			wait_for_preview_to_be_ready

			preview = Preview.reference
			preview.front_window.title.should == File.basename(jpg_test_file_path)
			preview.quit
		end
	end

	context "when preview decides 2 is the index of the front window" do
		it "should get front window" do
			`open -a Preview #{pdf_test_file_path}`
			wait_for_preview_to_be_ready

			preview = Preview.reference
			preview.front_window.title.should match /^#{File.basename(pdf_test_file_path)}/
			preview.quit
		end
	end
end

class Preview
...
	def front_window
		#ui is a reference to application "System Events" -> process 'Preview'
		front_window_index = ui.windows[1].name.get ? 1 : 2

		front_window = ui.windows[front_window_index]
		ApplicationScripting::Window.new front_window
	end
end _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Applescript Trivia: Black & White Pinwheel?
  • Next by Date: right click menu
  • Previous by thread: Re: Preview.app scriptable
  • Next by thread: Re: Preview.app scriptable
  • Index(es):
    • Date
    • Thread