This macro looks promising. I duplicated the steps shown on the site:
However, I could not get it to complete the process. It copied the URL in Safari, but did not return to the original app I was in and did not paste the URL there. Any ideas? Thank you.
Excerpt:
Keyboard Maestro is a really powerful tool for automating work on your Mac. Here’s a simple Keyboard Maestro script I use every day. When you write for the Internet, you often include links. This little script, upon me activating the magic keyboard combination, jumps to Safari, selects the URL (⌘L) then copies the link (⌘C), then jumps back the app from which I triggered the script and pastes the link at the current cursor location (⌘V). I’ve been doing this so long that it feels second nature. Below is a screenshot of the script along with a short video of the script in action. Enjoy.
Get Safari Link.kmmacros (3.1 KB)
Here are two possible solutions from Perplexity:
- Create a Keyboard Maestro macro that will upon me activating the magic keyboard combination, jumps to Safari, selects the URL (⌘L) then copies the link (⌘C), then jumps back to the app from which I triggered the script and pastes the link at the current cursor location (⌘V).
Here's a Keyboard Maestro macro that accomplishes the task you've described:
Macro: Copy Safari URL and Paste
-
Trigger: Set up a hot key of your choice (e.g., ⌘⌥C)
-
Actions:
-
Remember Current Application
- This stores the current app you're working in
-
Activate Safari
- Brings Safari to the foreground
-
Type the Keyboard Shortcut ⌘L
- Selects the URL in the address bar
-
Type the Keyboard Shortcut ⌘C
- Copies the selected URL
-
Activate Last Application
- Returns to the app you were using before
-
Pause 0.1 seconds
- Brief pause to ensure the app switch is complete
-
Type the Keyboard Shortcut ⌘V
- Pastes the copied URL at the cursor location
This macro will quickly jump to Safari, copy the current URL, return to your previous application, and paste the URL where your cursor is located[1][3]. The process happens rapidly, making it feel almost instantaneous.
To set this up in Keyboard Maestro:
- Open Keyboard Maestro and create a new macro
- Set the trigger to your desired hot key
- Add each action as described above
- Save the macro
Now, whenever you use the chosen hot key combination, it will execute this sequence of actions, allowing you to quickly insert Safari URLs into your current document or text field[5][7].
Remember that this macro assumes Safari is already running. If Safari isn't open, you may want to add a condition at the beginning of the macro to check if Safari is running, and if not, launch it before proceeding with the other actions[8].
Citations:
[1] Keyboard Maestro 4 Documentation: Macros
[2] manual:Macro Actions [Keyboard Maestro Wiki]
[3] Keyboard Maestro 5 Documentation
[4] Copy Safari Front Window URLs
[5] Example Macros to Get Started Using Keyboard Maestro
[6] Actions [Keyboard Maestro Wiki]
[7] Getting URLs from Safari - All this
[8] GitHub - treszkai/Keyboard-Maestro-macros: My list of macros for Keyboard Maestro
[9] Copying URLs with Keyboard Maestro : Ryan Jones
[10] Suggestions for Copy URL From Active Browser
and
Create an AppleScript that that will upon me activating the magic keyboard combination, jumps to Safari, selects the URL (⌘L) then copies the link (⌘C), then jumps back to the app from which I triggered the script and pastes the link at the current cursor location (⌘V).
Here's an AppleScript that accomplishes the task you've described:
on run
-- Remember the current application
tell application "System Events" to set frontApp to name of first process whose frontmost is true
-- Switch to Safari and copy the URL
tell application "Safari"
activate
tell application "System Events"
keystroke "l" using command down
delay 0.1
keystroke "c" using command down
end tell
end tell
-- Switch back to the original application and paste
tell application frontApp
activate
tell application "System Events"
delay 0.1
keystroke "v" using command down
end tell
end tell
end run
This script does the following:
-
It first remembers the name of the currently active application.
-
It then switches to Safari and uses keyboard shortcuts to select the URL (⌘L) and copy it (⌘C).
-
Finally, it switches back to the original application and pastes the copied URL (⌘V).
To use this script:
- Open Script Editor on your Mac.
- Paste the above code into a new script document.
- Save the script as an application.
- You can then assign a keyboard shortcut to this application using a third-party tool like Keyboard Maestro, Alfred, or macOS's built-in Automator[1][4].
Note that there are small delays (0.1 seconds) built into the script to ensure that each action has time to complete before the next one starts. You may need to adjust these delays depending on your system's performance[3].
Remember that for this script to work, it needs to have the necessary permissions to control your computer. You may need to grant it accessibility permissions in System Preferences > Security & Privacy > Privacy > Accessibility[2].
This script provides a quick and efficient way to copy URLs from Safari and paste them into other applications without manually switching between windows[6][8].
Citations:
[1] AppleScript "Copy Link" function for Safari - Ask Different
[2] Applescript to copy selected text plus pa… - Apple Community
[3] Paste text to last active window - AppleScript | Mac OS X - MacScripter
[4] How can one invoke a keyboard shortcut from within an AppleScript? - Stack Overflow
[5] Copy contents of specific web page - AppleScript | Mac OS X - MacScripter
[6] https://www.reddit.com/r/applescript/comments/xa3dvc/applescript_that_tells_safari_to_open_a_url_in_my/
[7] macos - Applescript to "paste" clipboard - Stack Overflow
[8] AppleScript: Launching Scripts From Links
[9] copy highlighted text in Safari to clipboard - effective newspaperclip - AppleScript | Mac OS X - MacScripter
[10] google chrome - Applescript to get the URL from Safari - Stack Overflow
Updated: Monday, 16 December 2024 11:43 AM NZ
The second solution by Perplexity seems to work: