{
  "title": "Read File to Clipboard",
  "cells": [
    {
      "type": "markdown",
      "data": "# Vanilla"
    },
    {
      "type": "code",
      "language": "applescript",
      "data": "use AppleScript version \"2.4\" -- Yosemite (10.10) or later\ruse framework \"Foundation\"\ruse framework \"AppKit\"\ruse scripting additions\r\rset theClip to current application's NSPasteboard's generalPasteboard()\rtheClip's clearContents()\r\rset thePath to \"/Users/tom/_Tmp ƒ/test-600.png\"\r--set thePath to \"/Users/tom/_Tmp ƒ/test.jpg\"\r\rset the clipboard to (read thePath as «class PNGf») # [1]\r--set the clipboard to (read thePath as JPEG picture) # [2]\r\rtheClip's |types|() as list"
    },
    {
      "type": "markdown",
      "data": "# ASOC"
    },
    {
      "type": "code",
      "language": "applescript",
      "data": "use AppleScript version \"2.4\" -- Yosemite (10.10) or later\ruse framework \"Foundation\"\ruse framework \"AppKit\"\ruse scripting additions\r\rset posixPath to \"/Users/tom/_Tmp ƒ/_PNG from PDF/test-1200.png\"\rset {theData, theError} to current application's NSData's dataWithContentsOfFile:posixPath options:0 |error|:(reference)\rset theClip to current application's NSPasteboard's generalPasteboard()\rtheClip's clearContents()\rtheClip's setData:theData forType:\"public.png\"\r\rtheClip's types() as list"
    },
    {
      "type": "markdown",
      "data": "### ASOC old - deprecated (Only and ever copies TIFF data to the clipboard, and fails on big data)"
    },
    {
      "type": "code",
      "language": "applescript",
      "data": "use AppleScript version \"2.4\" -- Yosemite (10.10) or later\ruse framework \"Foundation\"\ruse framework \"AppKit\"\ruse scripting additions\r\rset theClip to current application's NSPasteboard's generalPasteboard()\rtheClip's clearContents()\r\rset thePath to \"/Users/tom/_Tmp ƒ/test-600.png\"\r--set thePath to \"/Users/tom/_Tmp ƒ/test.jpg\"\r\rset theImage to current application's NSImage's alloc()'s initWithContentsOfFile:thePath\rif theImage is missing value then error \"Can't read image format\"\rtheClip's writeObjects:{theImage}\r\rtheClip's |types|() as list\r\r# Returns always: {\"public.tiff\", \"NeXT TIFF v4.0 pasteboard type\"}\r# Returns for big image data: {}"
    },
    {
      "type": "markdown",
      "data": "http://forum.latenightsw.com/t/how-do-i-copy-image-file-to-clipboard-and-retain-format/590"
    }
  ]
}