21
How to launch a GUI application using PySimpleGUI with a double-click on a mac
On mac, by creating a .sh
file in the form of .command
, you can execute that shell script file by double-clicking it.
Using this mechanism, I tried to launch a GUI application using PySimpleGUI by double-clicking the file.
Create a simple PySimpleGUI application that displays a list of theme colors provided by PySimpleGUI.
Save this code as display-theme.py
.
import PySimpleGUI as sg
sg.theme_previewer()
When you run this code, you will see a screen like this.
Let's actually create a .command
file.
Create the .command
file directly like this.
vim display-theme.command
Or, you can create a .sh
file, write your code in it, and then change it to .command
.
mv display-theme.sh display-theme.command
# Chnage current dir
cd `dirname $0`
# Run python script
python display-theme.py
echo $?
# Close the terminal by pressing any key
read a
When the .command
file is executed, the current directory is set to root
, so this command will take you to the location where the file exists.
cd `dirname $0`
This code is written as a confirmation. It just prints out an echo
to see if the execution is completed successfully.
echo $?
By including this description, the terminal will be closed by pressing any of the keys.
If this is not included, the terminal will close instantly, so it is also add to make sure that it was executed.
read a
Once you have created the shell script, give it execution permissions like this.
chmod u+x display-theme.command
At this point, your file directory should look like this.
.
├── display-theme.command
└── display-theme.py
You can then double-click this .command
file directly from the Finder to launch the GUI application with the theme color list.
This sample code is also available on GitHub.
21