Why does AppleScript open TextEdit before a list item is chosen?

I'm trying to create a substitute for a Templates folder (like Gnome) via an Automator service, but for some reason TextEdit app opens regardless. I've also tried tell TextEdit open file, but same thing happens.


on run {input, parameters}
	choose from list {"TXT", "PYTHON", "ZSH", "HTML"} with prompt "Choose a template" without multiple selections allowed and empty selection allowed
	set res to result as string
	if res = "TXT" then
		tell application "TextEdit"
			activate
		end tell
	else if res = "ZSH" then
		tell application "Visual Studio Code"
			open file ":Users:me:templates:script.sh"
		end tell
	else if res = "PYTHON" then
		tell application "Visual Studio Code"
			open file "Users:me:templates:starter.py"
		end tell
	else if res = "HTML" then
		tell application "Visual Studio Code"
			open file ":Users:me:templates:index.html"
		end tell
	end if
end run

Posted on May 9, 2022 4:25 PM

Reply
Question marked as Top-ranking reply

Posted on May 10, 2022 11:52 AM

The script works as expected (at least, substituting other apps since I don't have VSCode).


Therefore there's something else at play. Is this your entire workflow? Is there anything else in the workflow that could be calling TextEdit?

Similar questions

8 replies

May 11, 2022 2:24 PM in response to agent101

It's not uncommon for Script Editor (and, by extension, Automator) to launch the targeted app when you compile a script - this is sometimes necessary so the editor can extract the application's dictionary and know what commands it understands.


But that's only at compile time. This shouldn't cause the script to open an application at runtime, unless the app is specifically targeted.

May 10, 2022 5:26 PM in response to Camelot

Yeah I wondered about something along those lines. I did try a new workflow several times, it does this in the Script Editor too and in Shortcuts. It actually opens TextEdit when Automator opens, doesn't even wait to run the script. All of this seems buggy. I created keyboard shortcuts that would not work, change key combinations and it works, then change back to original and it works.


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Why does AppleScript open TextEdit before a list item is chosen?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.