21

I would like to create an application using AppleScript to copy the system info and email it to myself. I know to to do the emailing aspect and how to make the email have the content of whatever is in the clipboard. How might I use AppleScript coding to copy text to the clipboard?

In case it helps here is the way to email whatever is in the clipboard:

set a to "uselessdecoy@gmail.com"
tell application "Mail"
tell (make new outgoing message)
set subject to (the clipboard)
set content to "content"
make new to recipient at end of to recipients with properties {address:a}
send
end tell
end tell

2 Answers 2

32

You simply use

set the clipboard to "Some text"

You can also assign to the various parts of the clipboard (plain text, unicode, pict) directly, as in:

set the clipboard to {text:(outputText as string), Unicode text:outputText}
1
  • Is it possible to copy a binary file (i.e. mp4) from a given path to clipboard? Nov 27, 2022 at 20:11
0

JXA Example - Copying Safari URL and Title into Clipboard.

var appSafari = Application("com.apple.Safari");
appSafari.includeStandardAdditions = true


var winFront = appSafari.windows[0];
var winFrontName = winFront.name().split("\"").join("'");
var currentTabURL = winFront.currentTab().url();
var result = `${winFrontName}: ${currentTabURL}`;

appSafari.setTheClipboardTo(result)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.