Copy to Clipboard (Workspace Add-on)

2,643 views
Skip to first unread message

N A

unread,
Oct 25, 2022, 5:02:22 AM10/25/22
to Google Apps Script Community
Hi,

I have a Workspace add-on. I have a "Get Spreadsheet ID" button in the sidebar.  When user clicks, I want to copy to clipboard the current spreadsheet id.

I know I can't use the Clipboard API because Apps Script is not running in the browser. I'm looking at some NodeJs functions such as clipboardy to copy the id to clipboard, but not sure how to run this yet.

What solution do you have?

Thanks


Clark Lind

unread,
Oct 25, 2022, 9:18:02 AM10/25/22
to Google Apps Script Community
You may have to fall back to simply providing a modal dialog or alert box that gives the ID and/or even provide the direct url. Then they can do the clicking/opening. As you mentioned, since you are still working on the servers and not within the browser, I don't know how you can interact with the target OS.

Clark Lind

unread,
Oct 25, 2022, 9:19:19 AM10/25/22
to Google Apps Script Community
Or even just provide a direct link with the ID within a new card.

N A

unread,
Oct 25, 2022, 7:01:03 PM10/25/22
to Google Apps Script Community
Yes, I've implemented the fallback you mentioned - "provide the direct url". 

Regarding interacting with the target OS, there's a nice library clipboardy where it support multiple platforms. But not sure yet on how to import or run this in Apps Script. Have you tried running something like this before?

Thank you for your time.

Paul Armstrong

unread,
Oct 25, 2022, 11:28:57 PM10/25/22
to Google Apps Script Community
Hi
I have been meaning to get around to doing this myself. I have not confirmed this approach will work, but here is my thinking and the limited work I have done.

You need to be using an Editor Add-on (not Drive). From there, you can get a handle on the user's UI.

The following code will pop up a dialogue using the HTML in the CopyHtml.html file, which is another file in my GAS environment. 

SpreadsheetApp.getUi().getUi().showDialog(HtmlService.createHtmlOutputFromFile("CopyHtml.html"));

Regarding communicating with the server, google has an API that you can call from the client to the server. See https://developers.google.com/apps-script/guides/html/reference/host 
You may need to use Properties (https://developers.google.com/apps-script/reference/properties/properties-service) as a way of communicating between client and server calls. I had not gotten that far. But I figure it's doable. Then as your dialogue is on the client, it can (I hope) copy something to the clipboard. And the dialogue box can act as "I copied that for you" confirmation.

Good luck. Let us know how you get in. 

Ed Bacher

unread,
Oct 26, 2022, 1:11:22 PM10/26/22
to Google Apps Script Community
I have a Docs add-on that copies output to the clipboard successfully. The sidebar is running in the browser, and thus has access to the clipboad. I'm not that familiar with Sheets add-ons, but if you have a sidebar, that should also be running in the browser.

Here's the relevant code:

text.value = serverMessage;
    // Save the result to the clipboard (and add an error message if the write fails).
    navigator.clipboard.writeText(text.value).then(clipSuccess, clipError);
  }

The clipSuccess and clipError functions react to the result of the writeText() call.

You can see this in action if you install the Docs to Markdown add-on and convert a doc to Markdown or HTML. If all goes well, the converted text should be on the clipboard (no need to copy before pasting).

N A

unread,
Oct 26, 2022, 6:46:54 PM10/26/22
to Google Apps Script Community
Thank you Paul and Ed. Your solutions works well on Editor Add-on but currently developing this in Google Workspace Add-on.

Editor Add-on is running on browser but Google Workspace Add-on is not.

Ed Bacher

unread,
Oct 26, 2022, 8:30:35 PM10/26/22
to Google Apps Script Community
Ah -- good to know. I have a lot to learn about Workspace add-ons evidently!

Jason Cobble

unread,
Oct 26, 2022, 8:40:49 PM10/26/22
to google-apps-sc...@googlegroups.com
someone that has fraudulent control of my workspace identity and workspace cloud is emailing you guys and is added me to this list I have been working to get my workspace identity and Google cloud back in order to get them off of emm control of all of my devices and am looking for some help here I'd appreciate any pointers and any help you can give me because I would very much like to get my Google domains account back and my workspace account identity and a cloud identity and get them off of this emm on all my devices because they have complete control is still in my identity and it's a pain in the nuts any help or links to forums or running out that will give me some advice would be grateful for thank you....

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/0f170720-099a-4520-b319-7645a1a9e351n%40googlegroups.com.

N A

unread,
Oct 27, 2022, 11:14:45 AM10/27/22
to Google Apps Script Community
Yeah! Thanks Ed.

Looks like you're spamming, Jason "purism".

Jason Cobble

unread,
Oct 27, 2022, 11:18:56 AM10/27/22
to google-apps-sc...@googlegroups.com
You are not spamming me. My email is included here and or being forwarded to or from. They change it daily and the person there that said you were spamming me is one of the persons absuing the development center and software.

Jason Cobble

N A

unread,
Oct 29, 2022, 5:05:02 PM10/29/22
to Google Apps Script Community
Hi Jason, have you reported it to Google or changed your password?
Reply all
Reply to author
Forward
0 new messages