Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 23, 2013, 12:14 PM   #1
southpaw1017
macrumors newbie
 
Join Date: Jan 2013
AppleScript HELP!

Before I begin, I'm completely new to AppleScript but I am very familiar with the Mac Interface.

I'm using the application QuarkXPress to export files in a bunch of different formats. To increase my productivity, I made shortcuts for each of the menu commands. Now, to make myself even more productive, I'd like to make a script that will run each menu command for me, in order.

Anyway, here's the horribly offensive code I've have so far:
Code:
tell application "QuarkXPress" to activate
tell application "System Events"
	click menu item "Usage..." of menu "Utilities" of menu bar item "Utilities" of menu bar 1 of application process "QuarkXPress"
	tell application "System Events"
		click menu item "Collect for Output..." of menu "File" of menu bar item "file" of menu bar 1 of application process "QuarkXPress"
		tell application "System Events"
			click menu item "Layout as PDF..." of menu "Export" of menu item "Export" of menu "File" of menu bar item "File" of menu bar 1 of application process "QuarkXPress"
			tell application "System Events"
				click menu item "Layouts as Project..." of menu "Export" of menu item "Export" of menu "File" of menu bar item "File" of menu bar 1 of application process "QuarkXPress"
			end tell
		end tell
	end tell
end tell
Assuming a lot of you don't use Quark regularly and cannot test this code out for yourself, I'll tell you what happens. I get the first window (Usage...) to open up, but when I'm done with that page, the next window (Collect for Output...) does not open, and the code stops running for all I know. Sometimes, when I run the code one of the other commands will run, but when I am done using that the code will stop. Is there something I can write that will not run the next command until I close the current window?

Since I'm assuming you guys can't use Quark, could you try and make an example using another application, like Safari?

Thank you, and sorry for my lack of knowledge!!
southpaw1017 is offline   0 Reply With Quote
Old Jan 24, 2013, 08:56 AM   #2
superscape
macrumors regular
 
Join Date: Feb 2008
Location: Yorkshire, UK
Mmmm...

Hi there,

Personally, I'd use UI scripting as an absolute last resort - I've always found it a bit flakey. I've not scripted Quark Xpress for many years now, but as I remember it had quite a decent scripting dictionary. I'd strongly encourage you to use that if at all possible, only resorting to UI scripting if it turns out that what you need to do is otherwise impossible.
superscape is offline   0 Reply With Quote
Old Jan 24, 2013, 09:45 AM   #3
superscape
macrumors regular
 
Join Date: Feb 2008
Location: Yorkshire, UK
Ps...

Also, this might be helpful:

http://macscripter.net/viewtopic.php?id=23843


...and, looking at your code, do you really need *all* those nested 'tell app "System Events"' blocks?

Last edited by superscape; Jan 24, 2013 at 09:52 AM.
superscape is offline   0 Reply With Quote
Old Jan 26, 2013, 06:21 PM   #4
see.solve.
macrumors newbie
 
Join Date: Oct 2012
Sometimes the script is going at a faster speed than the interface scripting process. It might be helpful to put delay commands between some of the user interface commands.

Also, you can enclose some of the UI commands in a tell block instead of continuously typing out the name of the UI element (for example: tell application process "QuarkXPress" instead of ending all of the lines with: of application process "QuarkXPress"). And, you don't need to keep 'telling' System Events throughout the script.

Code:
tell application "QuarkXPress" to activate
	tell application "System Events"
		tell application process "QuarkXPress"
			tell menu bar 1
				click menu item "Usage..." of menu "Utilities" of menu bar item "Utilities"
				delay 1.1 -- number of seconds to wait; increase/decrease as needed.
				click menu item "Collect for Output..." of menu "File" of menu bar item "file"
				
				delay 1.8
				click menu item "Layout as PDF..." of menu "Export" of menu item "Export" of menu "File" of menu bar item "File"

				delay 2
				click menu item "Layouts as Project..." of menu "Export" of menu item "Export" of menu "File" of menu bar item "File"
			end tell
		end tell
	end tell
end tell
see.solve. is offline   0 Reply With Quote
Old Jan 27, 2013, 08:45 PM   #5
see.solve.
macrumors newbie
 
Join Date: Oct 2012
Argh. You know, I hate it when I post a question and I get a response from someone who has clearly not actually read my question. Please accept my apologies for skimming your query instead of reading it.

I don't know if this is the most efficient way, but what I do when I need the script to wait for a certain condition is use a repeat loop (example below). In this case, I'm assuming that clicking "Usage..." results in a window of some sort, so I have the script repeat delaying until the "Usage..." window has time to appear after I've clicked the "Usage..." button, and then have the script wait until the window no longer exists. Note that QuarkXPress may not consider them windows, in which case you'll need to refer to them differently. Also, I'm assuming their names match the menu items. You'll need to find out the proper names for the windows/UI elements. And, finally, we're no longer using 'tell menu bar 1' because, more than likely, window will not be an element of the menu bar. So, we've put 'of menu bar 1' back at the end of the 'click menu item' line.

Code:
tell application "QuarkXPress" to activate
	tell application "System Events"
		tell application process "QuarkXPress"
				click menu item "Usage..." of menu "Utilities" of menu bar item "Utilities" of menu bar 1
				repeat until (name of every window) contains "Usage"
					delay 0.5
				end

				repeat until (name of every window) does not contain "Usage"
					delay 1
				end
see.solve. is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Why so much Applescript? Dranix Mac Programming 25 May 2, 2014 01:05 AM
help with applescript andrewisgod Mac Programming 0 Apr 18, 2014 07:58 AM
AppleScript: How do I save multiple Excel sheets to one pdf using Applescript sbtaylor1 Mac Programming 0 Oct 28, 2013 11:38 PM
AppleScript: How do I save multiple Excel sheets to one pdf using Applescript sbtaylor1 Mac Applications and Mac App Store 0 Oct 28, 2013 11:32 PM
Help with an Applescript Theydonboi Mac Applications and Mac App Store 2 Nov 5, 2012 11:52 AM

Forum Jump

All times are GMT -5. The time now is 02:25 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC