How can I use KM to open a safari window in specific position?

How can I use KM to open a safari window in specific position and specific size?
It is like a pop up window。and has fixed size。such as 640*320px。

This should give you some ideas:

Hey @minjie_he,

AppleScript is faster and more organic (even though Keyboard Maestro’s actions actually use it under-the-hood).

------------------------------------------------------------------------------
set topLeftCornerX to 0
set topLeftCornerY to 23
set windowWidth to 640
set windowHeight to 320

set theURL to "https://google.com"

tell application "Safari"
   make new document with properties {URL:theURL}
   set bounds of front window to {topLeftCornerX, topLeftCornerY, topLeftCornerX + windowWidth, topLeftCornerY + windowHeight}
end tell
------------------------------------------------------------------------------

I wrote it that way for you to more easily enter the correct coordinates and dimensions.

Here’s how I’d do it on my system:

------------------------------------------------------------------------------
set theURL to "https://google.com"

tell application "Safari"
   make new document with properties {URL:theURL}
   set bounds of front window to {0, 23, 640, 343}
end tell
------------------------------------------------------------------------------

Here’s how to get the bounds of the front window:

------------------------------------------------------------------------------
tell application "Safari"
   bounds of front window
end tell
------------------------------------------------------------------------------

** Run this from the Applescript Editor.app, and you’ll be able to copy them out of the result panel.

You can resize the front window with JavaScript, but the above method seems to be faster when you also populate the URL of the document.

-Chris

1 Like

Here is a more intelligent macro (to give you some ideas) that will:

  • IF Safari is NOT Running, THEN Open default URL in new window
  • IF Safari is Running, THEN:
    • IF it has more than one Tab; THEN Move that Tab to new Window
    • ELSE Open new Window using URL of Safari main Window

This Macro is very fast, and much easier to change/maintain than a script.

You can, of course, easily change the Actions in magenta color to suit your preferences:

  • SET Default URL

    .
  • Move and Resize Front Window

##Macro Library   Open Safari Window with Set Position/Size


####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/2X/e/e0bc3af8de0d30feb97c3126fadae1cddb0acde5.kmmacros">Open Safari Window with Set Position-Size.kmmacros</a> (9.7 KB)

---

<img src="/uploads/default/original/2X/7/79c853e0fd993112e1942d3a68dde8f99c773d6f.png" width="564" height="1629">

thanks!and if there is any way make a url request as it is from iphone。so the web will give the webpage designed for Phone。I know Automator can achieve this,but can KM do this?

thanks!It works well!

If one of the above posts solves your problem/question as originally stated, please check the "Solved" checkbox (click for details) at the bottom of that post.

Otherwise, please post your remaining questions/issues about this problem.
If you have other questions, please start a new topic.