vitorgalvao / alfred-workflows

Collection of Alfred workflows
BSD 3-Clause "New" or "Revised" License
2.44k stars 167 forks source link

TemporaryEmail: Support for Arc Browser #168

Closed AnthoPakPak closed 1 year ago

AnthoPakPak commented 1 year ago

I've modified the workflow to support Arc Browser. You might be interested in updating it for other users (I don't think PRs are doable for Alfred Workflows).

Here's the Apple Script to open a new tab with passed url: osascript -e "tell application \"Arc\" to tell the active space of front window to make new tab with properties {URL:\"${url}\"}". The set active tab part isn't required for Arc since it automatically switches to the newly opened tab.

Which results in this script:

function notification {
  ./notificator --message "${1}" --title "${alfred_workflow_name}"
}

readonly email_name="${1//[^[:alnum:]]}"

if [[ "${service}" == 'harakirimail.com' ]]; then
  readonly email="${email_name}@harakirimail.com"
  readonly url="https://harakirimail.com/inbox/${email_name}"
elif [[ "${service}" == 'maildrop.cc' ]]; then
  readonly email="${email_name}@maildrop.cc"
  readonly url="https://maildrop.cc/inbox/${email_name}"
else
  readonly email="${email_name}@guerrillamail.com"
  readonly url="https://guerrillamail.com/inbox/${email_name}"
fi

readonly front_browser="$(osascript -e 'tell application "System Events" to return name of first process whose frontmost is true')"

if [[ "${front_browser}" == 'Safari'* || "${front_browser}" == 'Webkit'* ]]; then
  osascript -e "
    tell application \"${front_browser}\" to tell front window
      set tabIndex to index of current tab
      make new tab at after tab tabIndex with properties {URL:\"${url}\"}
    end tell
  "  > /dev/null
elif [[ "${front_browser}" == 'Google Chrome'* || "${front_browser}" == 'Chromium'* || "${front_browser}" == 'Opera'* || "${front_browser}" == 'Vivaldi'* || "${front_browser}" == 'Brave Browser'* || "${front_browser}" == 'Microsoft Edge'* ]]; then
  osascript -e "
    tell application \"${front_browser}\" to tell front window
      set tabIndex to active tab index
      make new tab at after tab tabIndex with properties {URL:\"${url}\"}
      set active tab index to tabIndex
    end tell
  "
elif [[ "${front_browser}" == 'Arc'* ]]; then
    osascript -e "tell application \"Arc\" to tell the active space of front window to make new tab with properties {URL:\"${url}\"}"
else
  notification 'You need a supported browser as your frontmost app'
  exit 1
fi

echo -n "${email}"
notification 'Temporary email address copied to clipboard'
vitorgalvao commented 1 year ago

I don't think PRs are doable for Alfred Workflows

They are, I do them regularly.

Here's the Apple Script to open a new tab with passed url: osascript -e "tell application \"Arc\" to tell the active space of front window to make new tab with properties {URL:\"${url}\"}".

So Arc is based on Chromium but has a different AppleScript dictionary to do the same thing? That means a whole new branch of support for a browser which isn’t even out for everyone. I’ll have to think about that, as their future is uncertain and I have a ton of workflows which support multiple browsers, this is far from the only one. This will require consideration. If Arc worked with the same AppleScript as Chrome, supporting it would be a no brainer, but as it is I cannot accept the change yet because I can’t test it.

Thank you for letting me know.

PS: For workflows with their own issue tracker, please use that instead. This repo will be deprecated once every workflow has moved.

AnthoPakPak commented 1 year ago

Thanks for your answer! To be honest, I was expecting Arc to be using Chromium Apple Script, and was surprised it doesn't. I'll suggest this to the Arc team, since for easier adoption, I agree it's a good idea to keep up with the existing Chromium dictionary.

I didn't knew your workflows now have their own repositories, thanks for letting me know.

(Btw, I can send you an invite if it's a matter of being able to test it)

vitorgalvao commented 1 year ago

I can send you an invite if it's a matter of being able to test it

That’s probably a good idea, thank you. It will allow me to look at it sooner. What information do you need? Assuming an email: [redacted]

AnthoPakPak commented 1 year ago

I've just sent you the invite. If you try it enough, you'll probably won't look back at Chrome anymore 😉

vitorgalvao commented 1 year ago

I’ll add support for Arc in an update later today. Worth noting Arc has no support for tab indexes in AppleScript, meaning that unlike other browsers it won’t be possible to open the tab in the background and return to the current tab.