Attach File To Gmail Message

I can’t find a shortcut in Gmail to attach files! Is there a way to use KM and maybe AppleScript to attach files to Gmail messages?

Hey There,

Yes. Here’s an AppleScript.

doJavaScriptInSafari("document.getElementsByClassName('wG J-Z-I')[0].click()")

------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------
on doJavaScriptInSafari(javascriptStr)
  try
    tell application "Safari" to do JavaScript javascriptStr in front document
  on error e
    error "Error in handler doJavaScriptInSafari() of library NLb!" & return & return & e
  end try
end doJavaScriptInSafari
------------------------------------------------------------

You can run the JavaScript string directly in KM’s Execute a JavaScript in Safari action if you want to

I can’t get it working in Chrome and won’t futz with it anymore.

You could also click the found image I expect.

To make this more robust I’d probably find the element with Xpath, but it’s too early to mess with that at the moment.

-Chris

Hey Chris,

Of course, I want this for work and use Chrome!

By the way, I purchased the AppleScript book you recommended. Do you recommend a RegEx guide or reference? I’ve look at Apple Store apps and read items found from Google searches. I still have not been able to parse the results from the Cmd-F directory code you provided.

Many thanks,

Anthony

Chris,

I’m such an IDIOT!

While it has been a learning experience investigating regex and applescript command languages, I finally fumbled onto the “Substring of variable” KM command which enables selection of the parts of item found by your shell script.

Duh!

Hey Anthony,

If you ask @ComplexPoint nicely he might help with Chrome and Xpath.

Here are some references for regular expressions.

https://wiki.keyboardmaestro.com/Regular_Expressions

-Chris