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 Aug 9, 2012, 11:31 AM   #1
ArtOfWarfare
macrumors 601
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
AppleScript help?

Hi, I tried typing my first script after looking at a few other ones, but it doesn't seem to be working... help would be appreciated.

Here's the script:
Code:
tell application "System Events"
	tell application process "ClipEdit"
		tell menu bar 1
			tell menu bar item "File"
				tell menu "File"
					tell menu item "New"
						tell menu "New"
							click menu item "Clipping from Clipboard"
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

delay 0.5

tell application "System Events"
	tell application process "ClipEdit"
		tell menu bar 1
			tell menu bar item "Edit"
				tell menu "Edit"
					click menu item "Copy"
				end tell
			end tell
		end tell
	end tell
end tell

delay 0.5

tell application "System Events"
	tell application process "Preview"
		tell menu bar 1
			tell menu bar item "File"
				tell menu "File"
					click menu item "New from Clipboard"
				end tell
			end tell
		end tell
	end tell
end tell
The error I get is this:
Quote:
error "System Events got an error: Access for assistive devices is disabled." number -1719 from menu bar 1 of application process "ClipEdit"
But I've found that this error is often spat out at incorrect times (according to a google search for it.)

What I'm doing is I'm taking a selection of shapes from an iWork app and copying it. Ultimately, I'd like it if they were copied as bitmaps with alpha values, but if I try to open them directly in Preview, Preview will add a white background to them all and interpret them as a PDF, not a bitmap.

Thus I go through ClipEdit, which automatically interprets the shapes as bitmaps with alpha values. I open a new document from the clipboard in it, it automatically interprets it, I hit copy, and then I open it in Preview, which then shows what I want. I then apply a crop, rotate, and export as a png. (Too many variables in there, so I see no point in scripting that portion.)

It's a workflow I'm familiar with and have done for over a year, don't question it, I'm just trying to speed it up a little by using a script.

Thanks

Edit: I anticipate the possibilty of being asked about ClipEdit, so here's a link to the dev's page. He offers it as a free download. Someday here I aught to donate to him given how much I use ClipEdit...

http://www.everydaysoftware.net/clipedit/

Edit 2X: Whoops... turns out it really was an assistive device issue.
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed.
Including the ones paired with other Macs on your network.

Last edited by ArtOfWarfare; Aug 9, 2012 at 12:25 PM.
ArtOfWarfare is offline   0 Reply With Quote
Old Aug 9, 2012, 11:52 AM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by ArtOfWarfare View Post
Edit 2X: Whoops... turns out it really was an assistive device issue.
I was going to suggest that you actually look and confirm that access for assistive devices was turned on. The debugging principle is this: check the most obvious things first.
chown33 is offline   0 Reply With Quote
Old Aug 9, 2012, 02:43 PM   #3
Mark FX
macrumors member
 
Join Date: Nov 2011
You can check and change the setting for the access for assistive devices in System Preferences, from within your Applescript if you want to automate it, let me know if you do and I'll post some code for you.

Regards Mark
Mark FX is offline   0 Reply With Quote
Old Aug 9, 2012, 11:56 PM   #4
ArtOfWarfare
Thread Starter
macrumors 601
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
All I had to do to make this script work was add in a few activate application commands (otherwise it's a little confusing whether it worked or not) - and activate the assistive devices in System Preferences.

I have a few more questions regarding AppleScripts...

1 - How can I get it to close windows?
2 - Is there some way for me to make a script pause, then wait for the user to tell it to continue? (IE, it'd be nice if it automated naming/saving/moving the files from Preview after I've modified them the way I want... that part is all pretty systematic.)
3 - Is there some way for me to have it grab the window that it made most recently, and then resize it to fill the screen?

The script works well enough without these functions, but I can see my workflow going even quicker and smoother (and being less mundane and dull) with these improvements.
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed.
Including the ones paired with other Macs on your network.
ArtOfWarfare is offline   0 Reply With Quote
Old Aug 10, 2012, 01:24 PM   #5
Mark FX
macrumors member
 
Join Date: Nov 2011
selecting a particular window of an application, and manipulating it is Application specific, that means that the particular application has to be scriptable, you can check to see if the application has a scripting definition file, or sdef dictionary file from the Applescript editor's, window library menu item.

for example the Finder Application has a limited number of methods for accessing its open windows.

Code:
tell application "Finder"
    set openWindowList to get name of every window
    return openWindowList
end tell
Gives an Applescript list with the title name of every open Finder window

Code:
tell application "Finder"
    close window 1
end tell
This closes the frontmost window, as the frontmost window is numbered 1, and the other open windows, are increasing numbers as to there position.

Code:
Tell application "Finder"
    close window named "Mark"
end tell
This close a Finder window with the name in the title bar of Mark, but will raise an error if no names window exists, but the first code snippet will give you the names of all open Finder windows, so check the name list first before trying to close it.

These are just a few of the type of commands that exist for the Finder application, but most of the Apple applications have the same or similar type of commands, like iTunes Preview ect.

So to awnser to your first question, check the particular applications scripting definition file for the properties and commands that can be accessed, alternatively you can do as you have been doing,
and script the GUI menu items for file close, or window zoom, he same as you've done in your original posting.

To pause a script you can use the standard delay command like this.

Code:
Tell application "Finder"
    close window named "Mark"
delay 2.5
end tell
This will only pause the script from executing the next line of code for a certain period of set time, alternatively you could run a repeat loop until a certain condition has been reached, like this.

Code:
repeat while conditionIsTrue
    delay 1
end repeat

--OR

repeat until conditionIsTrue
   delay 1
end repeat

--OR

repeat while not booleanExpression
    delay 1
end repeat
There is no actual pause command in Applescript as such, you have to create your own timers.

As for maximising a particular window, I would do the GUI scripting bit again, and click the window zoom menu item.

hope some of this helps.

Regards Mark
Mark FX is offline   0 Reply With Quote
Old Aug 10, 2012, 03:14 PM   #6
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by Mark FX View Post
There is no actual pause command in Applescript as such, you have to create your own timers.
You can also display a dialog or alert, with a timeout. So it pauses with a dialog, whose OK/Cancel then continues, or it pauses until the timeout expires. Syntax is display THING giving up after NN_SECS. There are many more options, so open the scripting dictionary StandardAdditions.osax (AppleScript Editor > FIle > Open Dictionary... ).
chown33 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 09:13 AM.

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

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