Sign in to follow this  
Followers 0
Hungry Dragon

Super Simple copy to clipboard script?

32 posts in this topic

Anyone know the best way to do a simple, powerful script so that when triggered by clicking on a field, the content of that field is copied to the clipboard?

Share this post


Link to post
Share on other sites

That would be the small normal script

Copy Field?

Make the field a Button and attach the script (I would also not allow entry in the field.

Maybe if you explained what you were trying to do, I could make it sexier. LOL

Lee

Edited by

Share this post


Link to post
Share on other sites

Basically I have a lot of layouts that have entry disabled to prevent accidental altering of the data, and instead have the users use a different 'editing' layout when they want to make changed.

However this also means that you can't just select the field content and copy it to the clipboard, if they want to the paste it into some email or word document the user is writing up. So to get around this the user goes to the 'editing' layout, just to copy the text. I don't like this, it opens the data up to accidental alterations, and adds seemingly unnecessary steps for the user.

So what I would like it to just have the uneditable fields act as a button that when clicked on the content of just that field gets copied into the clipboard so that the user can do whatever they want with it.

The problem I've encountered is that the copy command in scriptmaker either requires the target field to be specified, or it'll copy the whole record. But as I want to do this to something like 50 fields, having to write a different script for each one doesn't sound like fun, plus is bad programing methodology.

Have looked into using a variable, and can get the data i want to be put in a variable, can't figure out how to get that into the clipboard.

Any ideas or pointers greatly welcome.

Cheers,

--Dave

Share this post


Link to post
Share on other sites

Isn't that what I just said? :qwery:

You can create a separate layout if you want, but basically, you can lock the field in Layout Mode to not allow entry in Browse. Select the field, and attach the Copy Script step, and you don't have to go into Scriptmaker to do it, you can select it in the Button Setup Dialog.

Lee

Share this post


Link to post
Share on other sites

this may also be an appropriate technique

http://www.filemakermagazine.com/videos/copying-merge-fields.html

Share this post


Link to post
Share on other sites

You can create a separate layout if you want, but basically, you can lock the field in Layout Mode to not allow entry in Browse. Select the field, and attach the Copy Script step, and you don't have to go into Scriptmaker to do it, you can select it in the Button Setup Dialog.

I did try that, but it copies the whole record into the clipboard (as a long string of useless text noless), and all I want is the content of a specific field.

Share this post


Link to post
Share on other sites

don't use Copy ALL, use just Copy.

Lee

Share this post


Link to post
Share on other sites

you haven't selected a field.

Lee

BTW, you have only been talking about one field. There have been Topics in the past on this subject, if you are needing to copy more than one field, this would change things.

Other then wanting to paste the contents of a field into the Clipboard, you really haven stated why. Using the Clipboard should be avoided, especially since you could probably accomplish what you are after using one of the others, such as Set Field, Insert Calculated Result, Duplicate Record, etc.

HTH

Lee

Edited by

Share this post


Link to post
Share on other sites

Hello HungryDragon,

Using the Clipboard should be avoided, especially since you could probably accomplish what you are after using one of the others, such as Set Field, Insert Calculated Result, Duplicate Record, etc.

For me, I would "copy" or save the value of the record using variables. That would be easier, then if you want to "paste" the value, you can use "Set Field" or other functions...

Share this post


Link to post
Share on other sites

I still can't work out a good why to do this. At the moment the only option that works is to make a separate script for every field I want to be able to click on and copy the content to the clipboard. But the programmer in me just hates the idea of replicating almost identical scripts.

Share this post


Link to post
Share on other sites

What about a layout that has ALL calculated fields ?

The text inside them can be copied and even dragged and dropped, still preventing accidental altering of data.

Share this post


Link to post
Share on other sites

That is an interesting idea, it would work, but would require creating a calculated field for every field on a number of layouts... probably 100 or more extra fields, just so the contents is copyable... I will have to think this one over.

Share this post


Link to post
Share on other sites

... maybe you can give access to the user in this way ONLY to some relevant field, not to all.

Share this post


Link to post
Share on other sites

Oh, wow, that looks great. Simple, elegant, fast, flexible, my favorite sort of code. Will give it a go and let you know how I get on.

Share this post


Link to post
Share on other sites

Hi comment

why not a script of only one step:

Set field [ Table::gClipboard ; Get ( ScriptParameter ) ]

and let the gClipboard field enterable to the user for edit/copy/export ?

Share this post


Link to post
Share on other sites

Because that was not the request? True, the Insert Calculated Result[] can be replaced by Set Field[] - it makes very little difference here.

BTW, if you change gClipboard to type Container, it will work with all data types.

Share this post


Link to post
Share on other sites

Okay, have put it to work, its working perfectly. Exactly what I needed. Now I have to teach the users there is an easier way... :o

Share this post


Link to post
Share on other sites

Hi Michael,

In your PseudoSetClipoard file, I notice you end with Go To Field [ ]. I know, in older versions of FileMaker, there was no Exit Records/Requests or (now) Commit Records/Requests and so it was pretty common to use; at least I THINK that's what I've understood. But I thought that, now with Commit Records, Go To Field [ ] had been pretty-much dropped.

I am wondering if you have a specific reason for using it (you usually do) or whether it was old habit or simple preference. It seems like a small question but it is still important and if there are any subtle differences on when to use one or the other, I'd love to know it! Both, it seems, removes the cursor from any field and gives up possession of the record. So why use Go To Field [ ] ?

LaRetta :wink2:

Share this post


Link to post
Share on other sites

That's a good question. Until you've brought this up, I thought Go to Field[] would exit the active object without committing the record. Which is true, but there's a catch: the action is equivalent to clicking outside any object, so if the layout is set to save automatically, the record WILL be committed; if not, the script will be rudely interrupted by a message asking if you want to save the changes.

Seems like the only way to "deselect all" without committing is to place a dummy non-enterable object (e.g. text or a rectangle) on the layout, and use Go to Object ["dummy"].

Share this post


Link to post
Share on other sites

Well, I wondered if a global field took possession of a record. My test shows it does not. If this is correct, no commit would be necessary. BTW, I just opened a new window to test and have not (yet) run it by opening two simultaneous users to a served file. But I believe the results should be the same.

Share this post


Link to post
Share on other sites

A commit is NOT necessary - that's the point: I didn't want copy to have the side-effect of committing the record.

Share this post


Link to post
Share on other sites

I just meant that, since the cursor will be sitting in a global field, it won't be necessary to even remove the cursor; why can't it be left there when the script ends? I appreciate the input a great deal, thank you!

Share this post


Link to post
Share on other sites

Ah, gotcha ... because to put something onto the clipboard, we need to use Copy[] which requires Select Entire Contents and there is no way to hide it although one could go to another layout and back. I like your concept of using Go To Object ["Dummy" ] instead of layout hopping. One could also make the global field 1 px x 1 px and it wouldn't show at all.

Share this post


Link to post
Share on other sites

One could also make the global field 1 px x 1 px and it wouldn't show at all.

It would, if user started typing. It's not a "clean" solution.

Share this post


Link to post
Share on other sites

Oh, duh, of course! Agreed! Thanks for setting me straight!

Share this post


Link to post
Share on other sites

No, thank you. If you hadn't insisted, I wouldn't have discovered the limitation of Go to Field and the Go to Object ["dummy"] workaround. You have made yet another entry in the "Not in the Manual" document, which I am sure will please you to no end. :)

Share this post


Link to post
Share on other sites

It does indeed tickle me! I, like ChindoguMaker, enjoy discovering, uncovering or recovering strange things ... and even BEING strange things! :jester:

Share this post


Link to post
Share on other sites

A little bird hits my ear... :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0