newville / pyshortcuts Goto Github PK
View Code? Open in Web Editor NEWcreate desktop shortcuts to python scripts on Windows, Mac, or Linux
License: MIT License
create desktop shortcuts to python scripts on Windows, Mac, or Linux
License: MIT License
As far as I know, Windows icons use ones embedded in the DLL
or EXE
files.
While using pyshortcuts I'm forced to use static resolution of one image, and it looks very bad in most cases, as shown.
Is there a workaround?
A possible solution to this:
DLL
file (if it's possible - by some sort of developed wrapper) with rescaled icons. It could be created in the same directory each time that shortcut is made,I have tried this on both windows and macOS with the same results.
I have installed the pyshortcuts module and when executing 'pyshortcut -w' or 'pyshortcut --wxgui' I get the below error and the GUI window does not show up.
`pyshortcut: must provide one script. try 'pyshortcuts -h'
`
I made a shortcut and set SCRIPT as shell script on Mac book and the shortcut doesn't work.
However, if I modified /darwin.py:119 to #!/bin/sh (except #!/bin/bash), it can run successfully.
I don't know why this is happened....
Is there a way to set working directory for the shortcut/alias?
my command I am using to create the shortcut is:
make_shortcut("/Users/shift838/ooeyguiv4/output/ooeygui/ooeygui", name = "OoeyGUI", icon = "/Users/shift838/ooeyguiv4/output/ooeygui/images/og1.icns")
this creates the shortcut on the macOS desktop with no issue. but.. when executing it since I have it is looking for supporting files in the Desktop folder instead of the ooeygui application folder.
I think the envrunner
was changed in 1.8.1 or 1.8.2? I'm trying 1.8.2 now and I see a line like this:
call "%~dp0..\condabin\conda.bat" activate blah
That ../condabin
directory doesn't exist in the environment that I'm installing my package in, so this doesn't work. I think it is assuming you are installing in the base environment?
I was using 1.8.0 before, which worked fine. Should I update to a newer version? Or would that still be there?
I notice in fix_filename
it only allows one .
to be in the name. Was wondering on what platform this is a problem? It would be nice to be able to put a version number like 1.3.2
in the shortcut name. It's OK on Windows.
Thanks for this!
Gnome 3 doesn't really have a move-stuff-around desktop. The ~/Desktop
is still created, it seems, but the default file browser doesn't render .desktop
applications as anything other than text files, and clicking them just opens them in your text editor.
However, putting .desktop
files in ~/.local/share/applications/
will make them accessible to the launcher under the super key or hot corner. I was sceptical at first, but it's grown on me.
In some experiments, I've been successful in moving the generated shortcuts there, and they work fine, but as it becomes the default on more distros, it might be nice to offer detection of this. Happy to do some more research/PR if interested!
Hi, this has been a really great find for a project I'm working on (and hopefully many more to come). It has worked perfectly for me on MacOS, but the two Windows machines I've tried it on have had issues with the ENVRUNNER
set up. Specifically, it seems like the %~dp0%
in the call
line is unnecessary; removing that from the .bat
file makes the shortcut work. So, the ENVRUNNER
for them ends up looking like this:
ENVRUNNER = """
@ECHO OFF
call activate {0}
echo # run in conda environment "%CONDA_DEFAULT_ENV%":
echo # %*
start %*
""".format(conda_env)
and then works as intended, presumably since the file is already running from the conda env directory that is called by the %~dp0%
and thus only really needs the activate {env}
command. This might be due to a new Windows/conda update? But I figured I should mention it, since I'm 2 for 2 on that edit working on Windows.
Hello!
The work path (aka. working directory) is not a parameter of make_shortcut. Would it be possible to include it?
Thanks!
On Win10 using pyshortcut
command line script does not create .lnk in Startmenu (desktop link is still created though).
In 7b93151 I added a batch file to tests
that tries to:
timer.bat
If one tries to create a shortcut with an empty cmd it fails with the message AttributeError: 'NoneType' object has no attribute 'split'
.
cmd = shutil.which("my-script") # not in PATH, so returns nothing
scut = make_shortcut(cmd, name="My Script", icon=iconpath)
It could be more explicit about what's wrong. I'm not sure where's best place to put an error message, or very clear on the best practice for how.
totally up to up you of course, but I'd appreciate a new dot release so that a project I'm using pyshortcuts as a dependency in can take advantage of the recent conda envrunner and base-name-agnostic env fix. v1.7.1 would be fine (ie: wouldn't need to be 1.8)
If there's something else you'd like to put in before a new one, let me know how I can help. :-)
Would be possible to add an argument in the make_shortcut function to add the "-m" argument to the python executable? in that case the script string should be taken without adding any path before it and this would enable the possibility to execute module as scripts when a package was installed with an entry point
thank you
Hello!
I am using pyshortcuts on Linux. Here is code of my application which must create shortcut:
make_shortcut(
name='PyQtAccounts',
script=cwd + '/run.sh',
description='Simple account database manager.',
icon=cwd+'/img/icon.svg',
terminal=False,
desktop=desktop,
startmenu=startmenu,
executable='/bin/bash'
)
Everything is alright the shortcut appears in menu and desktop but there is no icon.
I looked on shortcut code, here it is:
[Desktop Entry]
Name=PyQtAccounts
Type=Application
Comment=Simple account database manager.
Terminal=false
Icon=/home/python/Downloads/PyQtAccounts/img/icon.svg.ico
Exec=/bin/bash /home/python/Downloads/PyQtAccounts/run.sh
If you look at this line:
Icon=/home/python/Downloads/PyQtAccounts/img/icon.svg.ico
and at this line in my code:
...
icon=cwd+'/img/icon.svg',
...
You'll see that i wanted the icon.svg not icon.svg.ico.
Can you fix this issue and make pyshortcuts to not add .ico for my icon path, please?
I used the python script to create a shortcut for my python application, and the final shortcut was like this:
[Desktop Entry]
Name=app_name
Type=Application
Path=/home/username
Comment=Here goes the application description.
Terminal=false
Icon=/home/username/app_folder/images/logo.ico
Exec=/usr/bin/python3
/home/username/app_folder/main.py
The application path is in another line, not in the same line as the python executable, and I have to remove that line manually to fix the shortcut.
Furthermore, the shortcut lacks one more thing that is vital for it to appear in the start menu, which is:
Categories=Utility;
There are a lot of categories to choose from, but Utility
could be the default choice when nothing is defined.
The issue happens with Kubuntu 22.10, and Python 3.10.
Thank you for this amazing utility, and I hope this issue is fixed soon.
Hi,
I have designed an app with Tkinter and I was using pyshortcuts library to create shortcuts at Desktop and Applications folders of Mac.
The shorctuts worked perfectly when I used Intel Mac Machine but they are not working when I am trying to create the at the M1 or M2 chip machines.
When I tried to access the contents folder of the app. The unix executable file inside MacOS folder is working correctly but these shortcuts when clicked are disappearing from the dock.
Below is the script which I used.
_**from re import sub
from pyshortcuts import make_shortcut
import subprocess
import TPLogger as lg
user = subprocess.getoutput('ls -l /dev/console | cut -d " " -f4')
ruta_user = f'/Users/{user}/Desktop'
ruta_app = f'/Applications'
make_shortcut('/opt/MyApp/MyAppScreen.py', name='MyApp', icon='/opt/MyApp/Resources/Images/MyApp.icns',terminal=True, folder=ruta_user)
make_shortcut('/opt/MyApp/MyAppScreen.py', name='MyApp', icon='/opt/MyApp/Resources/Images/MyApp.icns',terminal=True, folder=ruta_app)**_
Kindly suggest me some solution for the same. Thanks
Python version- 3.10
I would like the option to set the shortcut target to a relative path so that I can create a distributable folder with the shortcut and its target. (For me this would be as part of a pyinstaller bundle). This would obviously require the ability to set the location of the shortcut too.
Does this sound like something that would be possible/ people would be open to?
Please add Categories: according to free desktop .desktop rules. For better classification of the apps. Currently on KDE, the desktop files created by pyshortcuts fall under lost and found.
Sent from my Galaxy Note2 using FastHub
PYTHONEXECUTABLE should point at the output of sys.executable
Issue:
bin/python does not always exist the default build for python will generate bin/python. i.e. bin/python3.10
Using sys.executable should be sufficient to set this variable.
On a Windows machine using Conda to manage it's python environments some scripts need more help than just creating a shortcut to python path/to/script.py
. For example this will fail outside of conda activate xxxx
:
# needs-activation-to-run.py
import sqlite3
print("Sqlite version:", sqlite3.sqlite_version)
$ c:\apps\Miniconda3\envs\leo-dev\python.exe needs-activation-to-run.py
Traceback (most recent call last):
File "needs-activation-to-run.py", line 1, in <module>
import sqlite3
File "c:\apps\Miniconda3\envs\leo-dev\lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "c:\apps\Miniconda3\envs\leo-dev\lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
$ c:\apps\miniconda3\scripts\activate.bat leo-dev
(leo-dev) Matt@SERVER D:\Matt\code
$ c:\apps\Miniconda3\envs\leo-dev\python.exe needs-activation-to-run.py
Sqlite version: 3.29.0
Discovered downstream at leo-editor/leo-editor#1300
Great tool! This should be in the python standard library! I have been looking for this a long time. However, I still get a terminal when trying this on Windows using the terminal=False option. I looked at the code and I assume that wscript is not used to run the python script?
I have an app installed in an Anaconda environment, and the I manually create this vbs file:
Set oShell = CreateObject("WScript.Shell")
oShell.Run "cmd /C C:\Users\Utilizador\Anaconda3\Scripts\activate WIKIDPAD37 & C:\Users\Utilizador\Anaconda3\envs\WIKIDPAD37\Scripts\wikidpad.exe", false
Which actually works, no terminal is shown. The wikidpad.exe is an entry point created by setuptools. On the same installation I used pyshortcut:
make_shortcut( script='C:\\Users\\Utilizador\\Anaconda3\\envs\\WIKIDPAD37\\Scripts\\wikidpad',
name='wikidpadmp',
terminal=False,
icon='C:\\Users\\Utilizador\\Anaconda3\\envs\\WIKIDPAD37\\Lib\\sitepackages\\WikidPad\\wikidpad.ico')
This also works although I have some path issues and the fact that a command line window is shown. Is this a bug or do I have to do something else?
Thanks for your time.
in darwin make_shortcut function the script uses by default #!/bin/bash as shell, but in lastest macOS version the default shell is zsh.
Maybe the script could get default system shell from os.getenv('SHELL')
Is there a way to define the Python binary to be used in the shortcut?
I'm using poetry
if it matters
Adjacent to #1, I've been doing some post-processing of shortcuts. It would be nice if the convenient make_shortcut
returned the final written location (or the Shortcut
instance) such that it could be part of more complex pipelines.
Thanks again!
exception executing script
OSError: [Errno 22] Invalid argument: 'C:\\tools\\miniconda3\\envs\\leo-dev\\Scripts\\envrunner-C:\\tools\\miniconda3\\envs\\leo-dev.bat'
only 17 lines
--------------------
line 133: runner = os.path.join(sys.prefix, 'Scripts', runnerbat)
* line 134: with open(runner, 'w') as fh:
line 135: fh.write(ENVRUNNER)
line 136: time.sleep(0.05)
This is the bug I mentioned in #21, no time to dig in right now as I have to run out the door. It might be something in my code so don't spend much energy troubleshooting as it could be all my fault. ;-)
I'm exploring the possibility of using pyshortcuts to create menu and desktop launchers on multiple platforms for an application which is installed with pip and create console_scripts. So the application is started with PYTHONHOME\Scripts\appname.exe
and not python PYTHONHOME\Scripts\appname.exe
.
import shutil
appcmd = shutil.which('myapp')
if platform.system() == 'Windows':
leocmd = shutil.which('mywinapp')
from pyshortcuts import make_shortcut
make_shortcut(appcmd, name='MyApp', icon=iconpath)
Result using the desktop shortcut created with this:
File "C:\tools\miniconda3\envs\leo-dev\Scripts\myapp.EXE", line 1
SyntaxError: Non-UTF-8 code starting with '\x90' in file C:\tools\miniconda3\envs\leo-dev\Scripts\myapp.EXE on line 1, but no encoding declared;
see http://python.org/dev/peps/pep-0263/ for details
One fix for this could be to, on Windows only, have the shortcut call python PYTHONHOME\Scripts\myapp-script.py
instead of the path passed to pyshorcut. (*-script.py
is created by pip. I believe the name pattern to be stable but don't know if it can be relied on in perpetuity.)
Another option is to not hard code the python ...
prefix and just call the console script launcher directly and just rely on the OS to do the right thing. I can't speak to this being reliable on Linux and Mac.
A frustrating part of every institution I've worked at is that their IT always sets up my username as FIRSTNAME LASTNAME with a space in between. This is my current setup too and I think it is giving me issues now when I try to make a shortcut. Windows will accept
$C:/path/to/python.exe "C:/Users/first last/script.py"
as input with the quotes. Is there a way to use this instead to allow for paths with spaces in them?
Any plan for a new PyPI release? (so we can get the fix for #39).
The current pyshortcuts pypi release 1.8.2 contains a module pyshortcuts/base.py
which contains syntax / indentation errors.
May I suggest it's taken down and updated asap.
Is there a way to programmatically remove a shortcut created with pyshortcuts?
If not, I think it would be a nice feature
Thank you
Hi!
I'm trying to make a shortcut for an application executable file.
It is working perfect for Windows. However, on Linux it adds additional text to 'Exec=' row in .desktop file.
So, instead of this:
Exec='/home/oleg/Blender Builds/daily/blender-2.83-be7c51d076be-linux64/blender'
I got this:
Exec='/home/oleg/Blender Builds/daily/blender-2.83-be7c51d076be-linux64/blender' /home/oleg/Repositories/Blender-Launcher/source
Or even this one:
Exec=/usr/bin/python3 '/home/oleg/Blender Builds/daily/blender-2.83-be7c51d076be-linux64/blender'
How can I fix it?
Thanx!
Hi!
I think I am missing a tiny bit of background knowledge required to follow your instructions.
Readme.md states:
Of course, that command might be the sort of command you might want to be able to launch by clicking on a desktop shortcut. We have just the tool for that. This script (included as gui_bootstrap.py in the examples folder) will create a desktop shortcut that launches the pyshortcut GUI
..... where is the examples folder? And what is supposed to be done with this file once it's located?
I tried searching to no avail, but sometimes Spotlight doesn't see non-user files.
there is also this instruction which I think is related
~> python setup.py install
~> python examples/gui_bootstrap.py
but surely you need to be in some specific directory to run something called setup.py? I can't figure out where.
I would suggest it would be extremely handy to create an argument like --put-pyshortcuts-on-desktop
to handle this.
(Wow I never had occasion to think of a flag for anything before. It's hard! My first 10 ideas had letters already taken by other arguments. I'm sure you can think of a better idea though.)
thank you!
- from I am a person who is smart want to use python scripts, but not smart enough to make or fix them myself.
It turns out base
isn't a reliable name for the base environment, making activate base
cmd fail:
CondaEnvironmentNotFoundError: Could not find environment: base .
You can list all discoverable environments with `conda info --envs`.
# run in conda environment "":
# c:\apps\miniconda3\envs\leo-dev\Scripts\leo-messages.EXE
The other side of creating shortcuts is deleting them! ;-) It's unreasonable to have pyshortcut record where links are created; too many variable conditions to take into account, not least of which is where to save the record.
My naive but workable approach to a remove
command is: to create new shortcuts, which likely overwrite ones already there, and then immediately delete these new ones.
# create links
scut = make_shortcut(scriptcmd, name="Script Name", icon=iconpath)
lnkfiles = [os.path.join(scut.desktop_dir, scut.target), os.path.join(scut.startmenu_dir, scut.target)]
# remove links
for fil in lnkfiles:
os.remove(fil)
print(f"Removed '{fil}' ")
This would be slightly easier if scut returned the full path to the targets created.
I opened this issue for discussion and to share an idea. e.g. it's not a direct request to add a remove
function (though I'd be okay if it were).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.