How to "click" a button on website

In my day job, I work with a lot of Wordpress sites. Creating, designing etc.

Which way would be best to create a gesture to press publish, then go to the tab that has the permalink already open and refresh the page to see the changes?

Best regards

more context please. what apps are you using, what kind of gesture did you want -and when you say tab are you talking about a browsing tab in a browser like chrome/safari?

He probably wants to press website buttons and links in safari/chrome.

This would be a useful script, Bookmarked.

1 Like

Yes.
When I'm in a chrome browser, logged in to the backend of WordPress and editing a page, I'd like to make a gesture/shortcut.
When activated, look for the URL slug of the page being edited, click publish, find the chrome tab with the the URL slug found in step one and activate/bring to focus and finally refresh the page.

Hope it clarify your question, else please tell me

Here's a pseudo code as an example of what I'd like to achieve.

  1. Find id "sample-permalink" and copy the containing url
  2. Find input button with id "publish" and click
  3. If Chrome tab with above url exists, acitvate/focus tab, else open tab with above url
  4. Refresh page

I don't think we can target web elements with applescript as precise as that does...
I'm new to applescript though, so maybe someone else knows more.

You can use 'move mouse to position' actions to move the mouse to the location of the button and click it, though this isn't very stable as when you move the window around or resize it, the action may miss the button.

Try setting up your action:

  1. Add New Key Sequence (for keyboard) or Gesture (for trackpad)
  2. Assign the predefined action: 'move mouse to position'
    - set this depending on how the website's button moves around when you resize the window. If it's pinned to the top right, use relative to top right, etc.
  3. click "Attatch Additional Action"
  4. set this action to 'left click'
  5. Continue moving the mouse and clicking by this method to your satisfaction.

You should end up with something like:

Note: Insert delays to let the page load before continuing.

Also note: This isn't very stable as when you move the window around or resize it, the action may miss the button. Best practice is to target the buttons somehow using a script, but I don't know if something like that is possible.

This section is for completed / work in progress public presets. You may get more help while keeping this section cleaner by moving this thread to #discussion and questions.

Thanks for your suggestion. I can't use it though, because of position of the window plus the difference in pages. In the header of the back end, there can be several notifications from different plugins on different websites, so the position of the buttons is almost, always inconsistent.
I hope for another solution but thanks anyway :slight_smile:

It is possible to run javascript on a webpage, see this older post:

Using this it should be "easy" to trigger the functions you need. But of course this would still need some code depending on the website.

1 Like

hmmm my method is gonna require trial and error but it can work. im not really familiar with the sites so im gonna speak really broadly but

thats an app that comes with apple called actuator. it grabs urls like youre asking, but i havent tested it for your specific need.

this next one is keyboard maestro. it can search for specific pixel combinations or a picture or a color. you take a partial screen shot of something and you decide ho waccurate you want the match to be with the slider bar. you can choose to have it search for images on the window, a select area, a whole desktop, across all surfaces.

and as for searching and activating . the previous app has a applist viewer that lists each tab as a individual window and each window as a individual app. itll create a list of tabs and you can search from outside of chrome. but if that doesnt work theres a lot of tab manager add on's that will allow you to search, switch to tab, and refresh as a single command.

you can do all of this in btt and if you pref not to go into keyboard maestro you can create a applescript for that portion and let btt execute it.

one last thing, i would use a full command like 'refresh' frm context menu in app chrome etc vs using hot keys ilike cmd r for refresh in the list of commands. since its going across different programs you may have it trigger something unintentionally. better to be precise.

I think it would be easier to use a little Apple Script to trigger Java Script. Here is an example that gets the element with id ember911 and clicks it (you can get the id by right-clicking an element and selecting "inspect when using Google Chrome).

tell application "Google Chrome"
	execute active tab of front window javascript "window.document.getElementById('ember911').click();"
end tell

The only important thing is that Apple Events => Java Script is enabled in Chrome:

1 Like

OK, so far, I've come up with this code by looking at some tutorials and stuff.

tell application "Google Chrome"
set permaLink to execute active tab of front window javascript "
document.getElementById('wp-admin-bar-view').querySelector('a').href;"

execute active tab of front window javascript "
window.document.getElementById('publish').click();"

delay 0.5

repeat with w in windows
	set i to 1
	repeat with t in tabs of w
		if URL of t starts with permaLink then
			set active tab index of w to i
			set index of w to 1
			return
		end if
		set i to i + 1
	end repeat
end repeat
open location permaLink

execute active tab of front window javascript "window.location.reload()"

end tell

I've got three issues and hope you can help me with it.

It works, it searches for the permalink and save it as a variable. Publishes the post, look for a tab in current window with the permalink. If it exists, it sets to focus, if not, it creates the tab with the permalink.

First issue: The frontpage has usually "/frontpage" in the permalink eg. www.page.com/frontpage but when it loads, it redirects to www.page.com, so I tried to make an if statement saying that if the permalink contains "forside (frontpage)", remove that string from permalink variable or else it will create new tab even though it exists. No problem on other subpages, since they're not redirected.

Second issue: It only checks the active window so if the page is open in another Chrome window, it doesn't know and opens a new tab. Have tried some different things, without any luck.

Third and most important issue: I can't make it reload, once the permalink tab is in focus. The reload code works on it self but not in this code. I've also tried differen reload commands, both in JavaScript and Apple Script, without luck.

Did you improve this? interested as well

Imprint | Privacy Policy