Copying in all iWorks apps often gives No Text in Clipboard

I have a macro that pulls data from various Numbers spreadsheets and puts the date into our accounting program after doing some massaging of the date in variables and/or clipboards.

This year, however, the macro is choking on copying data from Numbers cells into the clipboard and having that data visible to Keyboard Maestro. Sometimes it does, sometimes it doesn’t. Even converted my spreadsheets to CSVs to open in Numbers and still had issue. The data can copy and paste but it is intermittently being recognized by KM in either a clipboard or variable. When I examine the variable/clipboard in KM preferences I keep seeing “No Text in Clipboard.”

Finally, in desperation, I switched to Numbers on iCloud and copying data from the spreadsheet through Safari is working now as KM seems to not have an issue getting clipboard data from Safari.

I am running the PB of 10.12.4 so not sure if that is the issue.

Updated: As noted by Tom below, this appears to be an issue that affects all three iWorks apps: Numbers, Pages and Keynote.

In order to help you, we need for you to post/upload your macro.
See

If you are doing a Copy for each cell in Numbers, you might want to consider using AppleScript to read each cell, and set the appropriate KM Variables. I think this would be much more reliable than a Copy-TAB approach.

If you do a Google search on "AppleScript Numbers", you should find lots of example scripts. You can also search this forum for the same.

At this point I’m getting frequent empty clipboards when I just use “Type the Command-C Keystroke” from within KM in a Numbers spreadsheet. It is intermittent…sometimes it recognizes there is data in the clipboard and sometimes it doesn’t.

This is nothing to do with the general macro nature of KM, it is just a bizarre glitch that I wanted others who might run into it to be aware of. I spent hours today trying to figure out what I was doing wrong.

AppleScript may be more reliable but I don’t have the familiarity and doing it through iCloud Numbers is capturing the data.

Instead of the KM Action "Type a Keystroke", you should use the "Copy" Action, which will make sure the copy to the Clipboard is completed, or give you an error.

I had tried that but it remained intermittent. Even using that, if I do a copy and then “Filter Clipboard with Remove Styles” I end up with No Text in Clipboard.

What is so strange is that doing copies with Safari there is no issue.

I can’t offer any more suggestions unless you post:

  • Your macro
  • Example Numbers file
  • Steps of your workflow

Yes, I can confirm this with Numbers, and also Pages and Keynote. Clipboard is “No Text in Clipboard” after the Remove Styles action. In other applications everything seems fine.

Inserting a pause doesn’t seem to help either.

The weird thing is, if I copy normally (⌘C without KM) and afterwards apply KM’s Remove Styles action, it’s OK.

I appreciate your help, but as Tom has confirmed it seems to be an iWorks/KM issue. Posting the macro or sample Numbers file is not going to really help as it is a general, not specific, issue.

I wonder if it has something to do with the new collaboration capability in iWorks?

On the other hand, posting a minimal working example can never harm, since it makes it easier for others to test it.

BTW, I noticed that it happens also without the Remove Styles action, but pretty rarely; whereas with Remove Styles it happens – almost – every time.

_[test] Copy from Numbers-Pages-Keynote.kmmacros (3.7 KB)

Thank you for posting the sample and for confirming this bizarre behavior.

Are you running the OS X Public Beta or a release version?

As you again correctly note it sometimes happens even without using the Remove Styles but then it is intermittent.

I’m running the release version here (10.12.3 (16D32)).

Pages, Numbers, Keynote are up to date, according to the App Store.

Just to followup, my macro is copying probably 20 cells worth of info and doing various tests/massages so the intermittent nature of it was really confusing. The macro kept failing or throwing out gibberish at random points in the process.

Just saw you are running the release version so we can rule out it just being a Public Beta issue. Thanks.

Hey James,

If you use the Clipboard Viewer utility to see what Numbers puts on the clipboard in the first place, you'll find an almost unbelievable number of data types.

It's not that surprising (to me) that your macro is choking on something here and there, although it looks like it might be a bug @peternlewis needs to address – as there is a simple NSSringPboardType available and a public.utf8-plain-text type available.

I'm curious about what data-types are in the worksheets that are failing.

Probably you're better off to extract your selection with AppleScript, process it in AppleScript, and then export to a Keyboard Maestro variable (or whatever).

Here's a basic script to put the values of the selected cells on the clipboard:

-------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/02/04 14:00
# dMod: 2017/02/04 14:31
# Appl: Numbers
# Task: Extract Text from Selected Cells and Place in a Keyboard Maestro Variable.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Keyboard_Maestro, @Numbers, @Extract, @Text, @Selected, @Cells, @Place, @Variable
-------------------------------------------------------------------------

tell application "Numbers"
   
   if document 1 exists then
      
      tell document 1
         
         tell active sheet
            
            try
               set activeTable to (the first table whose class of selection range is range)
            on error
               error "Something is wrong with the selection in the front document."
            end try
            
            tell activeTable
               set cellValues to value of cells of selection range
            end tell
            
            set AppleScript's text item delimiters to linefeed
            set cellValues to cellValues as text
            
            setKMVariable("numbersValues", cellValues) of me
            
         end tell
         
      end tell
      
   else
      error "Where is document 1"
   end if
   
end tell

-------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------
# Note that varName must be a string.
on setKMVariable(varName, varValue)
   tell application "Keyboard Maestro Engine"
      setvariable varName to varValue
   end tell
end setKMVariable
-------------------------------------------------------------------------

NOTE: I'm not sure this will work in all cases due to data-types, but it's working for me with text and date data-types right now on macOS 10.12.3 with Numbers 4.0.5.

If there are any failures they should be amenable to workarounds.

Now then – let's go really crazy and extract the public.utf8-plain-text data-type from the clipboard.

-------------------------------------------------------------------------
# Auth: Christopher Stone { Heavy Lifting by Shane Stanley }
# dCre: 2016/06/03 22:05
# dMod: 2017/02/04 14:47
# Appl: Keyboard Maestro
# Task: Extract public.utf8-plain-text data-type from the clipboard if available.
# Aojc: True
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Extract, @Keyboard_Maestro, @Extract, @public.utf8-plain-text, @Data-type, @Clipboard
-------------------------------------------------------------------------
use framework "Foundation"
use scripting additions
-------------------------------------------------------------------------

set kmPlistStr to missing value
set systemPasteBoard to current application's NSPasteboard's generalPasteboard()

if (systemPasteBoard's canReadItemWithDataConformingToTypes:{"public.utf8-plain-text"}) as boolean then
   # Copied public.utf8-plain-text
   set kmPlistStr to systemPasteBoard's stringForType:"public.utf8-plain-text"
end if

if kmPlistStr ≠ missing value then
   return kmPlistStr as text
else
   beep
end if

-------------------------------------------------------------------------

In general – run the AppleScripts from the Script Editor.app, before trying them from an Execute an AppleScript action, and look at the results in the result-viewer.

Although this won't work with the first script, because its result is placed into a Keyboard Maestro variable for you with cell values one per line.

The second script returns tab and LF delimited records.

It looks to me like you can make your process pretty bombproof, but only time and trial will tell.

If you run into any stumbling blocks let me know.

-Chris

1 Like

Hey Chris,

your Numbers script works fine here.

I don’t think it depends on the data types of the worksheet, since it happens also in Pages and Keynote (just copying some random lines of text).

Not sure, but that Clipboard Viewer from the App Store looks like a clone of Apple’s Clipboard Viewer.

Apple’s version is available from the developer downloads page as part of the “Additional Tools for Xcode” package:

Thanks. I’ll look at adding that and redoing the macro after I get the rest of the data entered for the tax year.

As an fyi, I’m no expert but I’m not sure if the data types are an issue.

I actually wondered about data types and set up the macro to enter the cell (option-return), select all the text in there (command-a) and copy that. Not being a programmer I would have thought that copying the data from within the cell would have gotten rid of most of the data type issues. May have made no difference as far as data types but it was all I could think of. Alas, it didn’t help with the No Text in Clipboard.

My cells have dates, text (names, addresses, phone numbers with dashes), currency with $ symbol (prices) and plain old numbers (fees/deposits, zip codes, phone numbers, quantity purchased)

Hey Tom,

Thanks for the heads-up on that. The Apple utility seems to work a little better than the one on the app-store.

-Chris

Hey James,

If you'll send me a worksheet off-list with sample data I'll write you a working script to extract it. (Link)

-Chris

OK, I sent sample files from our order sources and the macros I use to harvest the data to you in a private message

Hey James,

This will be easier if we can communicate via email instead of on the forum.

You can reach me at listmeister@thestoneforge.com

What I need to know right now:

A) Are you willing to install an AppleScript Extension?
– If so then please install the Satimage.osax (I’ve used it since 2003.)
– It adds all sorts of text an numerical processing commands to AppleScript.

B) Do you need to work with the selection in your spreadsheet, OR can you work with the whole table?

** Above is the direct download link for the Satimage.osax, but here’s the page it’s hosted on:

http://satimage.fr/software/en/downloads/downloads_nextsmile.html


Take Care,
Chris

Taken offline.