Copy & Paste Madness

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bbalmerTotalFluency
Posts: 52
Joined: Mon Apr 06, 2020 1:19 pm
Location: Thailand
Contact:

Copy & Paste Madness

Post by bbalmerTotalFluency » Wed Nov 15, 2023 2:37 am

Hi:

I wouldn't ask, but I've spent hours and I can't find what I'm looking for.

I have an iOS app with an iOS native text field with some text in it. I want to make a button that first selects all the text in the field and then copies it to the iPhone clipboard. I cannot find any reference to how to do that. If I had to guess (which has not been proving successful up till now), I'd guess something like

mobileControlDo "mData",selectAll" -- where mData is the name of the textfield
mobileControDo "mData","copy"

but guessing at commands is a very slow way to make progress.

I can select the text the normal way for iPhone and then copy it to the clipboard, so there is nothing wrong with my app or the mobileControl I have made - but I'd like to do so programmatically. Possible? How?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Copy & Paste Madness

Post by FourthWorld » Wed Nov 15, 2023 3:48 am

bbalmerTotalFluency wrote:
Wed Nov 15, 2023 2:37 am
Hi:

I wouldn't ask, but I've spent hours and I can't find what I'm looking for.

I have an iOS app with an iOS native text field with some text in it. I want to make a button that first selects all the text in the field and then copies it to the iPhone clipboard. I cannot find any reference to how to do that. If I had to guess (which has not been proving successful up till now), I'd guess something like

mobileControlDo "mData",selectAll" -- where mData is the name of the textfield
mobileControDo "mData","copy"

but guessing at commands is a very slow way to make progress.
Guessing is an adventurous choice, but not needed. The LC install includes a comprehensive Dictionary of all API calls -- see the Help menu.

In the entry for the mobileControlDo command I don't see options for "copy" or "selectAll". Have you seen those in production code somewhere, or was that just a guess?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bbalmerTotalFluency
Posts: 52
Joined: Mon Apr 06, 2020 1:19 pm
Location: Thailand
Contact:

Re: Copy & Paste Madness

Post by bbalmerTotalFluency » Thu Nov 16, 2023 4:23 pm

What's the word for a guess born of desperation? It was one of those.

I've looked in the dictionary, of course, but having found no reference to such a command did not know that that necessarily meant such a command didn't exist and that the listing was a full list of commands. Knowing that now (I'm assuming that is what you would have me realise) will save me a lot of time in the future. So, thanks.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Copy & Paste Madness

Post by FourthWorld » Thu Nov 16, 2023 9:06 pm

There are a few items that could be enhanced in the Dictionary, but for the most part they're pretty complete with current syntax options. The team puts in an effort to keep them updated as part of the time budget for new features.

But that still leaves your requirement outstanding: how do put things on the Clipboard without user intervention. On desktop LC makes this easy, as you noted. But on mobile I don't see an obvious solution.

I'll ask around, and look forward to seeing options provided here from other forum members.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Copy & Paste Madness

Post by stam » Thu Nov 16, 2023 9:17 pm

FourthWorld wrote:
Thu Nov 16, 2023 9:06 pm
I'll ask around, and look forward to seeing options provided here from other forum members.
There are a number of threads on this and 3 recent ones by @bbalmertotalfluency, all lamenting the same issue.

The upshot so far as I understand it:
- there is no mobile method for this
- at least on iOS it's likely this is locked out by Apple so only the user has direct access to the clipboard for security reasons (speculatively)

If the user wants to copy something they can do it manually.
If the developer needs to transfer data from one element to another the can do it without using the clipboard; this effectively sandboxes data between applications.

Perhaps a 4th thread is not needed (and perhaps direct contact with support at livecode dot com is advised if this is to be escalated?)
Stam

mtalluto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 125
Joined: Tue Apr 11, 2006 7:02 pm
Location: Seattle, WA
Contact:

Re: Copy & Paste Madness

Post by mtalluto » Fri Nov 17, 2023 1:24 am

Here is some code that we use in an app we made called Appli Player. It is used to capture data from native fields and put them into a variable. This code works on all platforms. This is immediately useful within the same app.

[Edit contains the result of this effort] I'll try putting it into the clipboard and see if other apps can access it on mobile devices.
I tried to get the updated clipboard to work in other apps and it would not. Every attempt to paste would result in data previous copied using the native field's method for copy (long press and use iOS UI to copy).

The screen looks like this...
player.jpeg

The Apply Code button has this switch statement in it.

Code: Select all

 switch platform()
          case "iphone"
               repeat with xControlNumber = 1 to 9
                    if xControlNumber = 5 then next repeat --SKIP HYPHEN
                    put mobileControlGet(gMobileAppCodeFieldIDa[xControlNumber],"text") after tAppCode
               end repeat
               break

          case "Android"
               repeat with xControlNumber = 1 to 9
                    if xControlNumber = 5 then next repeat --SKIP HYPHEN
                    put the text of widget gMobileAppCodeFieldIDa[xControlNumber] after tAppCode
               end repeat
               break

          case "macOS"
          case "win32"
               //DESKTOP
               repeat with xControlNumber = 1 to 9
                    if xControlNumber = 5 then next repeat --SKIP HYPHEN
                    put field ("appCode" && xControlNumber) after tAppCode
               end repeat
               break
     end switch
Last edited by mtalluto on Fri Nov 17, 2023 7:54 pm, edited 1 time in total.
Mark Talluto
--
Canela
design - develop - deploy: https://appli.io
Database and Cloud for LiveCode Developers: https://livecloud.io
Company: https://canelasoftware.com

mtalluto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 125
Joined: Tue Apr 11, 2006 7:02 pm
Location: Seattle, WA
Contact:

Re: Copy & Paste Madness

Post by mtalluto » Fri Nov 17, 2023 1:38 am

I found this video on YouTube that shows how it can be done in Swift.

https://www.youtube.com/watch?v=NehELQmkU_M
Mark Talluto
--
Canela
design - develop - deploy: https://appli.io
Database and Cloud for LiveCode Developers: https://livecloud.io
Company: https://canelasoftware.com

Post Reply

Return to “iOS Deployment”