1

I want to use applescript to place HTML data onto the clipboard from a text variable. I have at present a line of code that invokes applescript via the command line from my applescript.

set toUnixSet to "osascript -e \"set the clipboard to «data HTML" & hexString & "»\""

This is a little crazy. Can I not do this from applescript without a need for a re-invocation of applescript?

I copied data from firefox. I looked at what data class was on the clipboard via applescript (clipboard info). I want to place may own data on the clipboard in the same format as firefox delivered. I need only to have the HTML class data.

KJ explains how place HTML class data via the command line but, I am curious if I can do the setting from via native applescript code. I'm running macos 10.10.5. Basically, how to I substitute a text variable for the hex data "set clippy to «data HTML3C62723E49206B6E6F772069742773206F6C642C20627574204920686176656E2774207365656E20616E207570646174652E204C6F6F6B2E3C62723E3C62723E»". KJ explanation: https://stackoverflow.com/a/11089226/1360075

on run


    try
        set clippy to «data HTML3C62723E49206B6E6F772069742773206F6C642C20627574204920686176656E2774207365656E20616E207570646174652E204C6F6F6B2E3C62723E3C62723E»
        log clippy
        set the clipboard to clippy
        log (clipboard info)
    on error errMsg
        log " clippy error..." & errMsg
    end try

    -- This doesn't work, but it's as far as I got. 
    try
        set clippy2 to "3C62723E49206B6E6F772069742773206F6C642C20627574204920686176656E2774207365656E20616E207570646174652E204C6F6F6B2E3C62723E3C62723E"
        log clippy2
        set the clipboard to clippy2
        log (clipboard info)
    on error errMsg
        log " clippy2 error... " & errMsg
    end try

end run

This doesn't work, but it's as far as I got.

*«data HTML3C62723E49206B6E6F772069742773206F6C642C20627574204920686176656E2774207365656E20616E207570646174652E204C6F6F6B2E3C62723E3C62723E»*)
tell application "Script Editor"
    set the clipboard to «data HTML3C62723E49206B6E6F772069742773206F6C642C20627574204920686176656E2774207365656E20616E207570646174652E204C6F6F6B2E3C62723E3C62723E»
    clipboard info
        --> {{«class HTML», 64}}
end tell
(*«class HTML», 64*)
(*3C62723E49206B6E6F772069742773206F6C642C20627574204920686176656E2774207365656E20616E207570646174652E204C6F6F6B2E3C62723E3C62723E*)
tell application "Script Editor"
    set the clipboard to "3C62723E49206B6E6F772069742773206F6C642C20627574204920686176656E2774207365656E20616E207570646174652E204C6F6F6B2E3C62723E3C62723E"
    clipboard info
        --> {{Unicode text, 256}, {string, 128}, {scrap styles, 22}, {«class utf8», 128}, {«class ut16», 258}, {scrap styles, 22}}
end tell
(*Unicode text, 256, string, 128, scrap styles, 22, «class utf8», 128, «class ut16», 258, scrap styles, 22*)
  • The whole question is how to do set the html data class in the clipboard by native Applescript code. – historystamp Apr 23 '19 at 21:50
  • Take a look at these examples - stackoverflow.com/questions/11085654/… & hea-www.harvard.edu/~fine/OSX/cliphtml.html. – slm Apr 24 '19 at 5:30
  • 1
    I saw the first article and ended up with this line of code which invokes apple script from applescript: set toUnixSet to "osascript -e \"set the clipboard to «data HTML" & fromUnix & "»\"" Second article looks like a possiblity. – historystamp Apr 24 '19 at 17:23

You must log in to answer this question.

Browse other questions tagged .