Upload files through Google Chrome - google-chrome

So I'm about to attempt to upload several files through a Google Chrome Extension.
Instead of pressing the Upload button on the webpage and load each file one by one I want to automate it.
How should I go about this? Is it as simple as detecting the script inside the DOM responsible with uploading, changing the file_to_upload string from the scipt with a filename on my computer and injecting the new script and execute it ?

Related

How to direct Puppeteer downloads directly into Google AppScript

would appreciate if anyone can suggest ideas:
I currently have a Puppeteer script which automates CSV downloads into google drive which then allows me to programmatically access the data and move it into google sheets.
Currently, I run this locally on my computer on VS code. I don't yet understand all too well how to handle file downloads through puppeteer, but I currently have a work around by setting the default chrome download path to a folder on my computer, and that folder is actually Drive for desktop, so easy way to get files directly in drive.
await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: path.resolve('G:/My Drive/DriveData')});
Thing is, I'd like this to be some type of scheduled cloud function not having to be manually run on my computer. IF I were to do that, my Drive for Desktop work-around would not be viable. So is there a way I could pass the file download in Puppeteer directly into Google AppScript somehow? Or use the Drive API to directly receive the file?
My main issue is I don't understand how to actually handle file downloads in Puppeteer, I'm currently just editing the default download location for the google chrome instance puppeteer creates. I ultimately just need to get the data somewhere accessible by Google AppScript.
Any suggestions would be uber-appreciated!
I was also facing the same situation, unfortunately we cant install or use puppeteer in google app script environment,
The alternative is to do the file download using UrlFetchApp , cookies and sessions using session and cookies
The following code will help you save the file into Gdrive
var file = folder.createFile(UrlFetchApp.fetch("url of the downloaded file fetched dynamically"));
You need to check through the network logs in chrome to know how the file and on what URL request you are getting the file downloaded which you can pass to the function
Another alternative that will help you to download the file to drive is to use https://developers.google.com/drive
I had used python to save files in drive https://www.thepythoncode.com/article/using-google-drive--api-in-python

How do I discard changes in new Google Apps Script IDE?

I've been switched over to the new Google Apps Script IDE.
If I have multiple .gs and html files in one script document I used to be able to make changes on a file a close that without saving. Now the tabs are no more and you click directly on the filename and all you can do is undo until the file is reverted.
Is there a way to revert in one step?
thanks
The new code editor has no way to close an unsaved files' edit session. There is no good way to revert back to the last saved content. The only option you have is to close or refresh the browser tab. If you close or refresh the browser tab and you have other unsaved open file sessions that you want saved, then make sure to save the ones you want.

How can I print the Google Script I have written?

I want to print the Google script I have written (ultimately into a PDF) so I can send it to someone for them to look at.
I am unable to share the spreadsheet with them so I want to send it as another file but I don't want to lose the formatting. Not sure if this is possible but any help would be great. Thanks.
To export a static version of your code as displayed in the Apps Script Editor do the following: "Save Page As..." "Complete Webpage" on Chrome (other browsers will have corresponding method). Then share the resulting .htm file and folder. Delete all the .js files so that you don't get error messages. Done!
Here's an example folder you can download to see what the result looks like with javascript files deleted: https://drive.google.com/drive/folders/1eEhXJ7O7wc_uVzvzxIQ-ZpDnKA6HD_61?usp=sharing

Download image from url with google spreadsheet script

I'm using google spreadsheet app to parse information from a webstore. So far I've managed to get all the needed information except the images of products. I have the link to the image stored in a variable like this:
var test = 'http://.....image.jpg'
what I need to do is to download the image to my PC into any folder without any confirmation, since all of this will be done in a loop to download all the images from a webpage.

Creating a Google Apps Script which Automatically Executes on Upload

I have an interesting fairly simple problem I am trying to solve but I am at a loss on the proper code to get this to working correctly.
Basically, I have an very old local application running which allow me to print a receipt of a transaction. I have the ability to enable this receipt to be printed to a specific file within a specific directory on my computer or I can set it up to print out automatically to a printer on my computer. Currently I print the data out to a file, then copy the contents of that file and paste it into a word document template and then manually go through and format the data so it looks clean (I should note that the data prints out in fixed field format requiring a specific font and size so its pasts correctly. After all this is done I then email the word or pdf document out.
Essentially what I am trying to do here is automate this method and I thought this should be possible using a Google Apps Script.
My thought here was that it should be possible to:
save all the original files from my application to a specific
directory on my computer
sync that folder with google drive
have a google apps script automatically execute upon upload
have the google apps script automatically use a specific document
template I create with a header/footer and then paste all the
contents from the new file which was uploaded
have the google apps script pattern match certain elements within the contents of
the document and properly format it.
save the document to a specific location with a specific file naming convention
automatically email the document as a doc or pdf based upon a
specific regex matched field within the source document.
Could anyone provide a specific code example which demonstrates how Google apps scripts can be utilized to monitor the contents of a specific Google drive folder to trigger an event immediately after a new file is uploaded?
Thanks in advance!