The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniGraffle > OmniGraffle General
FAQ Members List Calendar Search Today's Posts Mark Forums Read

problem: copy as applescript | osascript - Thread Tools Search this Thread Display Modes
So, I draw a shape in Omnigraffle Pro (in this case a simple text box), and then select Save as applescript from the menu. I get the following results with osascript:

$ pbpaste | osascript -
131:138: syntax error: Expected , or } but found identifier. (-2741)
And here is a typical applescript, directly from pbpaste:
tell application "OmniGraffle Professional"
	tell canvas of front window
		make new shape at end of graphics with properties {side padding: 0, fill: no fill, draws stroke: false, draws shadow: false, autosizing: full, size: {20.000000, 14.000000}, text: {text: "abc", alignment: right, text: "abc"}, origin: {69.000000, 132.000000}, vertical padding: 0}
	end tell
end tell
This also happens with other shapes such as lines, rectangles, etc. What am I doing wrong?
The only thing you are doing wrong is expecting OmniGraffle to emit working Applescript code :-)

The first line needs to be

tell application "OmniGraffle Professional 5"
and if you make an intermediate stop in a text editor to fix that, I think you'll find that pbpaste | osascript - will work.
This bug is a very dear old friend I think I might miss it if it were ever unaccountably scheduled for decommissioning.

I remember, with great nostalgia, reporting it over two years ago to the Ninjas, and recording it here.

Cue to noble statement of policy on the democratic sequence in which bugs are fixed :-) (or, perhaps, sometimes, not fixed ...)
Incidentally, if it would just generate:

tell application id "OGfl"
that would be enough ...
Thank you. I knew it had to be something simple like that.

And yet, the name of the application (in /Applications, at least), is “OmniGraffle”. I never would have found the solution.
FWIW, I use this, as a LaunchBar script (tapping space-bar to enter part of the name of a running app) to find out how that application can be addressed through Applescript:

-- Get creator codes and bundle identifiers for tell applications blocks
-- (for applications currently running
-- Ver .05 Compatible with LaunchBar - select script, tap space bar and enter string in Launchbar

property pTitle : "Tell application id ..."

property pDefaultSearch : "omni"

property pCodeCopy : "Copy creator code"
property pBundleCopy : "Copy bundle identifier"
property pNameCopy : "Copy app name"

-- System Events
on run
	tell application id "sevs"
		set strSearch to text returned of (display dialog "Enter part of application name:
(or leave blank to see all running applications)" default answer pDefaultSearch with title pTitle)
	end tell
end run

on handle_string(strSearch)
	tell application id "sevs"
		if (strSearch ≠ "") and (strSearch ≠ "*") then
			set {lstCode, lstBundle, lstFile} to {creator type, bundle identifier, file} of (application processes where name contains strSearch and bundle identifier is not missing value)
			set strPrompt to "Applications with \"" & strSearch & "\" in their name:"
			set {lstCode, lstBundle, lstName, lstFile} to {creator type, bundle identifier, name, file} of (application processes where bundle identifier is not missing value)
			set strPrompt to "All currently running applications:"
		end if
		repeat with i from 1 to length of lstCode
			set varFile to item i of lstFile
			if varFile ≠ missing value then
				set strName to (name of item i of lstFile)
				set strName to item i of lstName
			end if
			set item i of lstCode to item i of lstCode & "=" & item i of lstBundle & "=" & strName
		end repeat
		set my text item delimiters to linefeed
		set strApps to lstCode as string
		set lstApps to paragraphs of (do shell script "echo " & quoted form of strApps & " | sort -t '=' -k 3")
		if length of lstApps > 0 then
			set lstDefault to {first item of lstApps}
			display alert "No running apps have names matching " & strSearch
		end if
		set varChoice to choose from list lstApps with prompt strPrompt default items lstDefault with title pTitle
		if varChoice is false then return
		set my text item delimiters to "="
		set {strID, strBundle, strName} to text items 1 thru 3 of first item of varChoice
		set {blnCode, blnBundle, blnName} to {true, true, true}
		if strID ≠ "????" then
			set strCode to "tell application id \"" & strID & "\""
			set blnCode to false
			set strCode to strName & " has no creator code ..."
		end if
		if strBundle ≠ "missing value" then
			set strBundle to "tell application id \"" & strBundle & "\""
			set blnBundle to false
			set strBundle to strName & " has no bundle identifier"
		end if
		if strName ends with ".app" then
			set strName to text 1 thru -5 of strName
			set strAppName to "tell application \"" & strName & "\""
			set blnName to false
			set strAppName to ""
		end if
		set strChoice to "CREATOR CODE:    " & strCode & "

BUNDLE IDENTIFIER:    " & strBundle & "

APP NAME:    " & strAppName
		set lstBtns to {}
		if blnName then set end of lstBtns to pNameCopy
		if blnBundle then set end of lstBtns to pBundleCopy
		if blnCode then set end of lstBtns to pCodeCopy
		set lngButtons to length of lstBtns
		if lngButtons > 0 then
			set strClip to "-- " & strName & return
			set strBtn to (button returned of (display dialog strChoice buttons lstBtns default button lngButtons with title strName))
			if strBtn = pCodeCopy then
				set strClip to strClip & strCode
			else if strBtn = pBundleCopy then
				set strClip to strClip & strBundle
				set strClip to strAppName
			end if
			set the clipboard to strClip & return & return & "end tell"
			display alert strName & " is not a scriptable process"
		end if
		set my text item delimiters to space
	end tell
end handle_string
It's hard to see how you didn't immediately recognize the problem from the error message :-)

I'll confess to wasting a bit of time fooling around with converting end of line characters and quoting before taking a completely different approach that led immediately to the solution...
A simple pre-breakfast memorisation exercise:

You will soon spot the system - OGfl contains a digit in the application title (which may or may not differ from the application name) but not the bundle code, whereas, of course, the OOut pattern is the converse, and none of this is relevant to RSGS, which doesn't start with an O. OFOC.

Or something of that general sort.

Attached Thumbnails
Click image for larger version

Name:	OmniAppAddresses.png
Views:	856
Size:	49.9 KB
ID:	2700  

Last edited by RobTrew; 2013-01-30 at 03:49 PM.. Reason: Clarification

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
applescript to copy an OmniGraffle graphic? supertwang AppleScripting Omni Apps 3 2011-12-08 10:56 PM
Copy and Paste Problem Bryan Applying OmniFocus 1 2010-11-08 09:16 PM
Glitch in: Edit > Copy As > AppleScript RobTrew OmniGraffle General 0 2010-04-15 09:11 AM
Weird copy/paste problem 2 wayne4 OmniFocus 1 for Mac 4 2008-10-31 04:01 PM
Weird copy/paste problem bbell2000 OmniFocus 1 for Mac 3 2008-10-30 02:52 PM

All times are GMT -8. The time now is 04:27 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2022, vBulletin Solutions, Inc.