0

I want to create a desktop icon in VSCode that will open a text file in my journal that I use on a daily basis. All I need to do is run the following command, code --new-window "diary.txt"

But I cannot open the terminal every time I write a diary. I want the above command to be executed by simply double clicking on the icon I have placed on my desktop.

I want to create a diary.command file, grant execute permission to the I have described the above command. The terminal window remains open at the same time as VSCode.

I cannot change the settings of the terminal itself. In Windows, this can be easily accomplished by creating a shortcut to the exe file and opening the properties screen.

I mentioned “diary” as an example. In fact, it is essential to execute any command line in hidden mode. So I am not looking for answers such as using VSCode extensions.

Security-wise, there should be no problem since I will be triggering the double-click on the icon myself. I am not talking about automatically executing the command in hidden.


I asked on Stack Overflow and was guided to this location as appropriate and resubmitted.

2
  • Look at Automater.app
    – mmmmmm
    Commented Jun 4 at 7:44
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Commented Jun 4 at 8:23

1 Answer 1

0

Create a shortcut.sh (or just leave out the extension to make it a "UNIX executable") file with content:

#!/bin/sh
code --new-window “diary.txt”

Then in terminal run chmod +x shortcut.sh

Put it on your desktop/dock, double click it, mission accomplished.

If this doesn't work, you can also write a simple C program that execve() "code".

As a less general approach, you can use vscode:// URL scheme as documented here.

2
  • Is there any way to just double click on the desktop icon like a normal app and have it run without opening a terminal other than the app?
    – Fushihara
    Commented Jun 5 at 2:11
  • If I remember correctly, my method would open app without terminal, as long as it is a UNIX executable rather than a shell script. I don't have a mac near me, but you can try it out.
    – hym3242
    Commented Jun 5 at 3:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .