Clipboard: Get contents of

This scriptlet retrieves the contents of the clipboard. Not as useless at it seems. You can use this in conjunction with the Copy to Clipboard action (System) to store file references for calling later. Very useful if your workflow does something that takes Finder item names out of the Data Flow.

--Return Clipboard Contents to Data Flow
return (the clipboard)


I call this (minipattern/idiom) “the reentrant clipboard”, which is a way to use the clipboard as a mediator of data, without disrupting the original contents of the clipboard, great when you are extracting text from PDF documents from withiin Safari. :slight_smile:

As with most things AppleScript; Nigel Garvey gave me the idea, or used it first.

set theSpare to the clipboard as record
tell application id "sfri" to activate
tell application id "sevs"
	tell application process "Safari"
		keystroke "c" using command down
	end tell
end tell
set extraction to the clipboard as text
set the clipboard to theSpare as record

The window in Safari needs to be active when you run the script, doing this.

When you’re using an do shell script you can pipe the output to the clipboard by sending the data to pbcopy. If you want to output of an shell command directly to the clipboard you don’t need the ‘set clipboard’ command. You can also use pbpaste to use something from the clipboard directly in the shell, so you don’t need the ‘get clipboard’ command.

--setting the clipboard contents
do shell script "echo 'Hello world!' | pbcopy"

--getting the clipboard contents (get's the mail addresses from the text of the clipboard)
do shell script "egrep -o '[a-z][a-z\\.-_]*@[a-z\\.-_]*\\.[a-z]{2,4}' <<< $(pbpaste)"