• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Javascript to copy clipboard contents to selected form field description?

Contributor ,
Jan 06, 2022 Jan 06, 2022

Copy link to clipboard

Copied

Is there a way to copy clipboard content to the description of the form field i have selected?Screen Shot 2022-01-06 at 1.55.38 PM.png

TOPICS
How to , Scripting

Views

864

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Jan 06, 2022 Jan 06, 2022

Hello @LynxKx,

 

Give the below code a try...

 

 

function Main() {

  function GetClipboard(){  
    var clipboard;  
    if(File.fs == "Macintosh"){  
        var script = 'tell application "Finder"\nset clip to the clipboard\nend tell\nreturn clip';  
        clipboard = app.doScript (script,ScriptLanguage.APPLESCRIPT_LANGUAGE);  
    } else {  
        var script = 'Set objHTML = CreateObject("htmlfile")\r'+  
        'returnValue = objHTML.ParentWindow.ClipboardData.GetData("text")';  
        c
...

Votes

Translate

Translate
Contributor ,
Jan 06, 2022 Jan 06, 2022

Copy link to clipboard

Copied

Clarifying. I'm also trying to set multiple properties and assign a shortcut to the script.

Ideally, I'd like to copy the content I want for the form field description, select the form field, activate the script which would then:

  • copy clipboard elements to description
  • check 'multiline'
  • uncheck 'scrollable'
  • change font to Arial, Auto, Regular

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jan 06, 2022 Jan 06, 2022

Copy link to clipboard

Copied

Hello @LynxKx,

 

Give the below code a try...

 

 

function Main() {

  function GetClipboard(){  
    var clipboard;  
    if(File.fs == "Macintosh"){  
        var script = 'tell application "Finder"\nset clip to the clipboard\nend tell\nreturn clip';  
        clipboard = app.doScript (script,ScriptLanguage.APPLESCRIPT_LANGUAGE);  
    } else {  
        var script = 'Set objHTML = CreateObject("htmlfile")\r'+  
        'returnValue = objHTML.ParentWindow.ClipboardData.GetData("text")';  
        clipboard = app.doScript(script,ScriptLanguage.VISUAL_BASIC);  
    }  
    return clipboard;  
} 

myDescriptionText = GetClipboard();

	try { 
        mySelObject.properties = {
        appliedFont: "Arial",
        fontSize: 0,
        fontStyle: "Regular",
        description: myDescriptionText,
        multiline: true,
        scrollable: false

        }} catch(e) {}
    }
  
  if (app.selection.length == 0) {
	alert("Error!\nNothing is selected.");
   }

  else if (app.selection.length > 1) {
    alert("Error!\nThere's more than one object selected.");
  }

  else if (app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline")) {
	alert("Error!\nThere's some text selected.");
   }

  else if (app.selection[0].constructor.name != "TextBox") {
    alert("Error!\nNo form field Text Box is selected.")
  }

  mySelObject = app.selection[0];

  Main();

 

 

Regards,

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 06, 2022 Jan 06, 2022

Copy link to clipboard

Copied

Beautiful! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 12, 2022 Jan 12, 2022

Copy link to clipboard

Copied

a couple things:

  1. Ive been getting wuite a bit of lag when I run this script, sometimes its fast but lately it has about a minute delay. I put an alert when its finished so I know when its done, otherwise it just seems like my file froze. any thoughts why this might be happening?
  2. Will this script work on a PC?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jan 13, 2022 Jan 13, 2022

Copy link to clipboard

Copied

LATEST

Hello,

 

I've ran the script on a few different files and I haven't seen any lag time or delay in its execution.

I don't have a way to actually text to see if it will work on a PC or not but it should.

Could you post one of the documents that your'e seeing the lagging issue for troubleshooting purposes?

 

Regards,

Mike

 

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines