Copying in all iWorks apps often gives No Text in Clipboard

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.

Hey Tom,

Numbers holds various data internally differently than what it displays.

The easiest way to work with that is to get the formatted value of a cell instead of the value.

-Chris

Hey Folks,

James and I have worked pretty extensively on this problem off-forum, and here’s an example of what I’ve learned in exploring Numbers’ AppleScript dictionary.

AppleScripting Apple’s Numbers Spreadsheets

Getting the data directly spares us all problems related to using the clipboard.

-Chris

Has @peternlewis confirmed this issue? I know that @Tom and I have both seen it in action.

Has anyone compiled a detailed bug-report and sent it to the Keyboard Maestro support address?

While Peter reads the user forum, all serious support requests should be routed appropriately:

https://www.stairways.com/main/contact

-Chris

No, I have not investigated this issue. Without some sort of repeatable case or at least some way of duplicating the issue, I can’t really investigate it. I don’t use Numbers myself often enough to see any issue if there is one.

My first guess would be that you are selecting a cell and Numbers is putting information about the cell on the clipboard rather than the text, or that Numbers might be putting either an old style styled text or some iWork internal format on the clipboard and not plain or RTF text, but really there is not enough information for me to make any kind of a judgement on what might be the issue.

I have sent you a mail with a minimal macro, a Numbers test file and instructions how to reproduce.

The odd thing is, as I tried it a couple of days ago, I got the same “No Text in Clipboard” also in Pages and Keynote. Today however it occurs only in Numbers.

I tried @Tom’s test and it worked every time (30+ times) for me.

So perhaps there is some other confounding part of the puzzle, maybe some other clipboard app or something else mucking around with the system.

Yes, I think you can replace the “perhaps” with “without a doubt”.

I have quit the obvious suspects (LaunchBar, Typinator, and a couple of others) but this changes nothing.

But, finding third-party interferences is rarely a straight-forward thing :wink:

Since I’m not using any clipboard macros with Numbers, I will not invest more time in this. But, of course, if I find the cause someday by accident, I’ll let you know.

Options would be trying after Safe Booting and creating a new (or Guest) account and trying there.

That only really tells you how deeply the problem is situated though, but it may give some sort of lead if the problem does not appear in either of those cases.

For whatever it’s worth (probably not much), I can add that I’ve seen “No Text in Clipboard” when copying from applications other than the iWork apps — but I wasn’t logging my actions at the time and can’t recall exactly where.