Jump to content
OmarKN

positioning 2 (Safari) webpages, after macro

Recommended Posts

Hi and good day,

How can I position 2 (Safari) webpages, LEFT and the other RIGHT after my ALFRED OPEN URL macro, where I call 2 urls,

and I want them side by side.

 

I guess it could also be done with an AppleScript positioner script after launching the pages?!

 

/

with best regards,

Omar K N

Stockholm, Sweden

Share this post


Link to post

And how are you introducing the two URLs? Are you giving them to a Keyword (say, by separating them with commas), or are they always the same?

Share this post


Link to post

They are 2 static urls, no keywords.

The Alfred macro (hotkey trigger) opens first url1 in Safari, then it opens url2 in a new tab.

 

The intent is to have them side-by-side.

 

Maybe it would be enough to have 1 command of some sorts, so as to open url2 in a new Safari *window* and positioning it to the right half of the desktop.

 

I have this script, but with Safari Tabs I don't know:

 

tell application "Safari" to set bounds of front window to {150, 25, 1368, 1299}

 

2009876799_ScreenShot2019-09-17at08_38_03.thumb.png.af7899c346da5ce3bd185cabbbe241da.png

 

/
Any assistance would be greatly appreciated!

With best regards,
Omar KN

 

 

Share this post


Link to post

Here's a script that accepts one or more URLs as command-line arguments, and opens windows for each one, evenly distributed across the screen:

 

var safari = Application('Safari');

function screenSize() {
  return Application('Finder').desktop.window.bounds();
}

function openWin(url, bounds) {
  var doc = safari.Document().make();
  doc.url = url;
  var win = safari.windows[0];
  win.bounds = bounds;
}

function run(urls) {
  var bounds = screenSize(),
    height = bounds.height,
    width = bounds.width / urls.length;

  var x = 0,
    y = 0;

  urls.forEach(function(url) {
    var bounds = {'x': x, 'y': y, 'width': width, 'height': height};
    openWin(url, bounds);
    x += width;
  });
  safari.activate();
}

So if you saved the script as browsers.js, you could use it in a Run Script action (Language = /bin/zsh) like this:

urls=("https://www.example.com")
urls+=("https://www.othersite.com")
urls+=("https://www.someplace.com")

/usr/bin/osascript -l JavaScript browsers.js $urls

 

Edited by deanishe

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...