简体   繁体   English

如何在Python中为Linux创建URL快捷方式?

[英]How to create an URL shortcut for Linux in Python?

As you see in the question, I am trying to create an URL shortcut in Python for both Windows and Linux. 正如您在问题中看到的那样,我正在尝试在Python中为Windows和Linux创建URL快捷方式。

Windows shortcut is working, this is my code if somebody needs it : Windows快捷方式正在运行,如果有人需要,这是我的代码:

import os

target = "www.google.com"
with open(os.path.join(shortcut_path, "windows_shortcut.url"), "w") as f:
   f.write('[InternetShortcut]\n')
   f.write('URL=%s' % target)

But for Linux it is an other problem and I can't find any solution which is working for me with google. 但是对于Linux来说,这是另一个问题,我找不到与Google合作的解决方案。

This is what I tried : 这是我尝试的:

import os

target = "www.google.com"
with open(os.path.join(shortcut_path, "linux_shortcut.url"), "w") as f:
    f.write("""[Desktop Entry]
    Encoding=UTF-8
    Name=Link to google              
    Type=Link
    URL=%s
    Icon=text-html
    Name[en_US]=commit""" % target)

Thanks for your time 谢谢你的时间

顺便说一句,解决问题的方法很简单,只需将linux_shortcut.url替换为linux_shortcut.desktop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Windows 10 中使用带有 python 的 URL 创建快捷方式 - Create a shortcut using URL with python for windows 10 如何在python 3.3中为命令创建快捷方式 - How To create a shortcut for a command in python 3.3 如何为我的 python 文件创建一个 powershell 快捷方式 - How to create a powershell shortcut for my python file 如何创建指向 python 中文件夹的 windows 快捷方式 - how to create a windows shortcut to a folder in python 如何为与 PyInstaller 捆绑的 Windows、MacOS 和 Linux 应用程序创建快捷方式图标 - How to create shortcut icons for Windows, MacOS and Linux applications bundled with PyInstaller Python - 使用参数创建快捷方式 - Python - Create Shortcut with arguments 如何在云端硬盘中创建重定向到特定网址的快捷方式 - How can I create a shortcut in Drive that redirects to a specific url 我将如何创建一个在 python 中运行异步函数的键盘快捷键? - How would I create a keyboard shortcut that runs an async function in python? 如何创建导入最常用的python模块的快捷方式? - How do I create a shortcut to import most used python modules? 如何使用Python(Ubuntu)创建桌面快捷方式? - How do I create a desktop shortcut with Python (Ubuntu)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM