Clipboard: "paste with original style" by applescript or JS


#1

Is there a way to complete “paste with original style” or equivalent of menu command (⌥⇧⌘V) instead of “paste” (⌘V) by applescript
example copy/paste from Safari to OO:

tell front document
  set last_row to row -1
  set topic of last_row to (get the clipboard as string) -- > simple paste
-- or
  set topic of last_row to (get the clipboard) -- > simle paste
-- or
  set topic of last_row to do shell script "pbpaste" -- > simle paste
-- or
  set topic of last_row to (get the clipboard as record) -- > OmniOutliner got an error: Can’t make {«class weba»:«data weba6262706C6973743030D10 ... etc}
end tell

If exists solution by JS via console it would be great too…

Thnx in advance…


#2

You can try with this code:

Applescript

on run
	tell application "OmniOutliner"
		set oDoc to front document
		pbpaste at (end of children of oDoc)
	end tell
end run

#3

Thnx for answer!
Command syntax of this

pbpaste at location specifier ¬ -- required
     from text -- optional

location specifier is - The location at which to paste the nodes.

so with (end of ...) it makes multiple rows if I copied several lines and
I can’t change topic’s value of existing row

pbpaste at topic of row   -- return_error_as_expected
end

In other words (pbpaste) makes new location and can’t change the existing? I got this right?
If it so…
How to get the value of pbpaste (clipboard) as “original style” instead of string?
Is there any other way to handle this command pbpaste?
I’ll think further about it…


#4

You’re welcome.

It’s an insertion point. You are specifing the point where nodes are going to be created. It’s a relative object specifier.

In this case, at end of children is this location.

If you want to read more about that:

Parameters That Specify Locations - AppleScript Language Guide

pbpaste mimics the behaviour of menu command paste with original style, I think. If you copy some text and click that menu item, it will create new row(s) below child collection. It will not overwrite existing and does not return any value.

If you tell me more about what your specific use case, maybe I come up with a solution.


#5

Yes, I’m understanding. Thanks for the reference.
So I can’t assign object specifier to a variable, or return it as a value.
It’s apparently the reason for that pbpaste makes multiple row if I copy more than one line.

My routine tasks are copy/paste from Safari to Outliner’s row topic.
But each line of clipboard are becoming as the new object by pbpaste. And I expect from this copy/paste that it will be paste into the topic of single row.

expectations - if I copied inside the Safari and pasted inside the OO:
clipboard_exp
the result by (pbpaste) - if I copied inside the Safari and pasted inside the OO:
clipboard_not_exp

probably I’ll have to merge created rows into the single row
p.s. But If the copy was made inside the OmniOutliner then the command of pbpaste do the paste by one row.


#6

pbpaste makes a row for each line in the clipboard text, I think.

You can try this code. It’s using GUI Scripting to accomplish what you want.
Usage:

  • Select OO Row whose topic is going to be appended.
  • Select text in Safari
  • Run script
on run
	activate application "Safari"
	delay 1
	
	tell application "System Events"
		tell process "Safari"
			keystroke "c" using command down
		end tell
	end tell
	
	activate application "OmniOutliner"
	delay 1
	
	tell application "System Events"
		tell process "OmniOutliner"
			keystroke return using command down
			delay 1
			set oMenuItem to menu item 8 of menu 1 of menu bar item 4 of menu bar 1
			click oMenuItem
		end tell
	end tell
end run

That’s right. I think it makes a lot of sense because, otherwise, it would split into new rows each topic that happens to have more than 1 paragraph. In this case, the clipboard contains OO data.


#7

unlocked2412, Million thanx
this example is very useful for my initial knowledge of applescript!


#8

You’re welcome, bikeNik. I’m glad it helped. Good luck on your learning!

EDIT: This code successfully replaces content on topic of selected code. Old code appended, instead.

on run
	activate application "Safari"
	delay 1
	
	tell application "System Events"
		tell process "Safari"
			keystroke "c" using command down
		end tell
	end tell
	
	activate application "OmniOutliner"
	delay 1
	
	tell application "System Events"
		tell process "OmniOutliner"
			keystroke return using command down
			keystroke "a" using command down
			set oMenuItem to menu item 8 of menu 1 of menu bar item 4 of menu bar 1
			click oMenuItem
		end tell
	end tell
end run

P.S. GUI Scripting is always the last resort.