# Suggestion to shortcut to open new tab in Chrome with predefined url with input

**URL:** <https://community.folivora.ai/t/suggestion-to-shortcut-to-open-new-tab-in-chrome-with-predefined-url-with-input/27616>\
**Category:** Configuration Help & General Discussion\
**Created:** [July 8, 2022, 9:02am UTC](https://community.folivora.ai/t/suggestion-to-shortcut-to-open-new-tab-in-chrome-with-predefined-url-with-input/27616 "2022-07-08T09:02:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Davallen](https://community.folivora.ai/user_avatar/community.folivora.ai/davallen/32/22348_2.png) [@Davallen](https://community.folivora.ai/u/Davallen)\
**Post date:** [July 8, 2022, 9:02am UTC](https://community.folivora.ai/t/suggestion-to-shortcut-to-open-new-tab-in-chrome-with-predefined-url-with-input/27616/1 "2022-07-08T09:02:32Z")

</div>

Hi, I'm looking for suggestion to this example in Chrome.

1. Shortcut to open an input field
2. Type "en" and hit enter  
2.1 If url contains anything between **.com** and **/login** ([example.com/us/login](http://example.com/us/login)) then replace us with **en** from input  
2.3 If url does not contain anything between **.com** and **/login** ([example.com/login](http://example.com/login)) then add **/en** in between .com and /login = [example.com/en/login](http://example.com/en/login)
3. Open [https://example.com/en/login](https://example.com/en/login) in new tab

I'd like it to work like Spotlight. CMD + space \> type app name \> ENTER to open app.  
But with the logic of replacing XX with whatever is being typed in the input field.

Is this even possible?

---

<div class="post-metadata">

**Author:** ![Frank1](https://community.folivora.ai/letter_avatar_proxy/v4/letter/f/a87d85/32.png) [@Frank1](https://community.folivora.ai/u/Frank1)\
**Post date:** [July 8, 2022, 3:54pm UTC](https://community.folivora.ai/t/suggestion-to-shortcut-to-open-new-tab-in-chrome-with-predefined-url-with-input/27616/2 "2022-07-08T15:54:51Z")

</div>

Since no one answers ... with my limited knowledge, I think it can not be done. You can try Keyboard Maestro. 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![Davallen](https://community.folivora.ai/user_avatar/community.folivora.ai/davallen/32/22348_2.png) [@Davallen](https://community.folivora.ai/u/Davallen)\
**Post date:** [July 11, 2022, 9:15am UTC](https://community.folivora.ai/t/suggestion-to-shortcut-to-open-new-tab-in-chrome-with-predefined-url-with-input/27616/3 "2022-07-11T09:15:45Z")

</div>

I am pretty sure it can be done with a mix of AppleScript and Javascript

---

<div class="post-metadata">

**Author:** ![Davallen](https://community.folivora.ai/user_avatar/community.folivora.ai/davallen/32/22348_2.png) [@Davallen](https://community.folivora.ai/u/Davallen)\
**Post date:** [July 11, 2022, 9:17am UTC](https://community.folivora.ai/t/suggestion-to-shortcut-to-open-new-tab-in-chrome-with-predefined-url-with-input/27616/4 "2022-07-11T09:17:49Z")

</div>

I made it work with apple script. Here is the code if anyone else will do something similar.

```auto
set startURL to "https://example.com/"
set endURL to "/login/"

set theCountrycode to ""

repeat while theCountrycode is ""
	set theCountrycode to ¬
		the text returned of ¬
			(display dialog "Enter the countrycode:" default answer ¬
				"" buttons {"Cancel", "OK"} default button 2)
end repeat

tell application "Google Chrome"
	activate
	tell front window to make new tab at after (get active tab) with properties {URL:startURL & theCountrycode & endURL} -- open a new tab after the current tab
end tell

```

---

<div class="post-metadata">

**Author:** ![Andreas\_Hegenberg](https://community.folivora.ai/user_avatar/community.folivora.ai/andreas_hegenberg/32/39221_2.png) [@Andreas\_Hegenberg](https://community.folivora.ai/u/Andreas_Hegenberg)\
**Post date:** [July 11, 2022, 11:07am UTC](https://community.folivora.ai/t/suggestion-to-shortcut-to-open-new-tab-in-chrome-with-predefined-url-with-input/27616/5 "2022-07-11T11:07:45Z")

</div>

Yep I think using this sort of Apple Script is currently the most performant way to achieve this.  
The Shortcuts app does not yet have an action to open a url in a new tab, otherwise that would have been my recommendation (it works well with BTT and getting & working with text it is really easy (and it will be the future of automation on macOS)).  
If you want to minimize the use of Apple Script and use it only for opening the new tab:

 ![image](https://community.folivora.ai/uploads/default/original/3X/4/c/4c2625db61f3bc9a29c4fdc1aa78eb138e872f2e.jpeg)

---

<div class="post-metadata">

**Author:** ![Davallen](https://community.folivora.ai/user_avatar/community.folivora.ai/davallen/32/22348_2.png) [@Davallen](https://community.folivora.ai/u/Davallen)\
**Post date:** [July 12, 2022, 6:44am UTC](https://community.folivora.ai/t/suggestion-to-shortcut-to-open-new-tab-in-chrome-with-predefined-url-with-input/27616/6 "2022-07-12T06:44:11Z")

</div>

Thanks Andreas, that's an awesome solution I think it will always be best to use native solutions.  
Changed mine to the one you provided using Shortcuts.
