def shortcutBuild(video): target_path, relpath = createFormatPath(video) # role base for role in video.roles: path = os.path.join(format_role, role["name"]) if not os.path.exists(path): os.makedirs(path) winshell.CreateShortcut(Path=os.path.join(path, video['_id']) + ".lnk", Target=target_path) # score base score = str( int(0 if video.score is None or video.watch_num < 5 else video.score)) path = os.path.join(format_score, score) if not os.path.exists(path): os.makedirs(path) winshell.CreateShortcut(Path=os.path.join(path, video['_id']) + ".lnk", Target=target_path) # images target_path = os.path.join(img_path, video.img) if os.path.exists(target_path) and not os.path.exists( os.path.join(format_images, video['_id'] + ".jpg")): shutil.copy(target_path, os.path.join(format_images, video['_id'] + ".jpg"))
def create_shortcut(directory, boolean): desktop = winshell.desktop() start_menu = winshell.start_menu() if boolean == 1: pythoncom.CoInitialize() winshell.CreateShortcut(Path=os.path.join(desktop, "PyPassMan.lnk"), Target=directory + '\\PyPassMan.exe', StartIn=directory, Description='PyPassMan') elif boolean == 2: pythoncom.CoInitialize() winshell.CreateShortcut(Path=os.path.join(start_menu, "PyPassMan.lnk"), Target=directory + '\\PyPassMan.exe', StartIn=directory, Description='PyPassMan') elif boolean == 3: pythoncom.CoInitialize() winshell.CreateShortcut(Path=os.path.join(desktop, "PyPassMan.lnk"), Target=directory + '\\PyPassMan.exe', StartIn=directory, Description='PyPassMan') pythoncom.CoInitialize() winshell.CreateShortcut(Path=os.path.join(start_menu, "PyPassMan.lnk"), Target=directory + '\\PyPassMan.exe', StartIn=directory, Description='PyPassMan') elif boolean == 0: pass
def start_client(): ##Missing excel import functionality. Excel spreadsheets coming. ## Need to add pin to the taskbar for each client. client_list = os.listdir(client_root) openf = input("Enter client's info:Lastname_number :\n") # Bool to find if the folder already exists file_exists = False for client in client_list: if client == openf: file_exists = True break else: continue # Creating a new folder if new client if file_exists == False: os.mkdir(r"C:\Users\anton\OneDrive\Desktop\Working folder\Client Base Hidden\%s" % openf) # Creating shortcut new_client = r"C:\Users\anton\OneDrive\Desktop\Working folder\Client Base Hidden\%s" % openf winshell.CreateShortcut( Path = os.path.join(os.getcwd(), "%s.lnk" % openf ), Target = new_client, Icon = (new_client,0)) #Opening workspace. Once Excel wb added, it will be opened here as well. os.chdir(new_client) os.startfile(new_client)
def OK_buttonClick(self): settings = [ self.spinBox_1.value() if self.checkBox_1.isChecked() else 0, self.spinBox_2.value() if self.checkBox_2.isChecked() else 0, self.spinBox_3.value() if self.checkBox_3.isChecked() else 0, self.spinBox_4.value(), ] settings = [str(s) for s in settings] # generate link in startup directory = path.dirname(sys.argv[0]) target = path.join(directory, "BingWallpaper.exe") arguments = ' '.join(settings) winshell.CreateShortcut( Path=path.join(winshell.startup(), "BingWallpaper.lnk"), Target=target, Arguments=arguments, StartIn=directory, ) # messagebox question, ask to download ans = QMessageBox.question(self, "创建配置", "成功配置开机启动!\n是否立即执行程序?", QMessageBox.Ok | QMessageBox.Cancel) if ans == QMessageBox.Ok: ShellExecute(0, 'open', target, arguments, directory, 1) self.close()
def create_shortcut_unfrozen(): """Creates a desktop shortcut for the Antecedent Precipitation Tool""" # Define Shortcut Variables python_path = 'C:\\Antecedent Precipitation Tool\\WinPythonZero32\\python-3.6.5\\python.exe' desktop_path = str(winshell.desktop()) # get desktop path icon = "C:\\Antecedent Precipitation Tool\\images\\Graph.ico" launch_script = '"C:\\Antecedent Precipitation Tool\\Python Scripts\\ant_GUI.py"' shortcut_path = os.path.join(desktop_path, 'Antecedent Precipitation Tool.lnk') description = 'Launches the Antecedent Precipitation Tool, written by Jason C. Deters' # Create shortcut shortcut_exists = os.path.exists(shortcut_path) if not shortcut_exists: print( 'Creating Desktop shortcut for the Antecedent Precipitation Tool...' ) else: print('Validating Desktop shortcut...') winshell.CreateShortcut(Path=shortcut_path, Target=python_path, Arguments=launch_script, StartIn=desktop_path, Icon=(icon, 0), Description=description) print('') print( 'All Elements installed successfully! Closing window in 5 seconds') time.sleep(5)
def create_lnk(target, lnkdir=None, filename=None, description="", is_desk=False): """ 创建快捷方式 :param target: 指向路径 :param lnkdir: lnk保存路径 默认与target同目录 :param filename: 快捷方式名称 默认target :param description: 备注 :param is_desk: 是否为创建桌面快捷方式 :return: """ try: if is_desk: # 桌面快捷 lnkdir = winshell.desktop() elif not lnkdir: # 当前路径 lnkdir = os.path.dirname(target) # 默认原文件名 filename = filename if filename else os.path.basename(target) # 文件全路径 file_name = os.path.join(lnkdir, os.path.basename(filename) + ".lnk") winshell.CreateShortcut( Path=file_name, Target=target, Icon=(target, 0), # 文件备注 Description=description) print('create lnk success, path: %s' % file_name) except Exception: raise
def create_shortcut_frozen(): """Creates a desktop shortcut for the Antecedent Precipitation Tool""" # Define Shortcut Variables module_path = os.path.dirname(os.path.realpath(__file__)) root_folder = os.path.split(module_path)[0] frozen_exe_path = '{}\\Antecedent Precipitation Tool.exe'.format( root_folder) desktop_path = str(winshell.desktop()) # get desktop path icon = "{}\\images\\Graph.ico".format(root_folder) shortcut_path = os.path.join(desktop_path, 'Antecedent Precipitation Tool.lnk') description = 'Launches the Antecedent Precipitation Tool, written by Jason C. Deters' # Create shortcut shortcut_exists = os.path.exists(shortcut_path) if not shortcut_exists: print( 'Creating Desktop shortcut for the Antecedent Precipitation Tool...' ) else: print('Validating Desktop shortcut...') print('') print('') print('') print('') print('') winshell.CreateShortcut(Path=shortcut_path, Target=frozen_exe_path, StartIn=desktop_path, Icon=(icon, 0), Description=description) print('')
def on_modified(self, event): for filename in os.listdir(folder_to_track): if filename == 'Games': continue if filename == 'desktop.ini': continue if filename.startswith('~'): continue if filename.startswith('.'): continue if not filename.endswith('.lnk'): # create_shortcut() program_files = winshell.programs() target = f'{folder_to_track}{filename}' winshell.CreateShortcut( Path = os.path.join(folder_to_track, f'{filename}.lnk'), Target = f'{folder_to_track}/{filename}') # move_file() file_exists = os.path.isfile(f'{folder_destination}/{filename}') if file_exists: while file_exists: new_filename = f'({self.i}) - {filename}' self.i += 1 file_exists = os.path.isfile(f'{folder_destination}/{new_filename}') os.rename(f'{folder_to_track}/{filename}', f'{folder_destination}/{new_filename}') else: os.rename(f'{folder_to_track}/{filename}', f'{folder_destination}/{filename}')
def create_startup(): startup = winshell.startup() # use common=1 for all users print(startup) winshell.CreateShortcut( Path=os.path.join (os.getcwd(), "WallpaperHour.exe"), Target=sys.executable, Icon=(sys.executable, 0), Description="Wallpaper Hour" ) winshell.CreateShortcut( Path=os.path.join (winshell.startup(), "WallpaperHour.lnk"), Target=sys.executable, Icon=(sys.executable, 0), Description="Wallpaper Hour" )
def CreateShortcut(lnkFileLocation, targetFullPath, targetWorkingDir): #from win32com.client import Dispatch import winshell from os import path # The shortcut icon is the same as the source exe file. winshell.CreateShortcut(Path=lnkFileLocation, Target=targetFullPath, StartIn=targetWorkingDir, Icon=(targetFullPath, 0), Description='') if path.isfile(lnkFileLocation) is not True: raise FileNotFoundError( "Shortcut create failed:\n\t{}".format(lnkFileLocation)) #shell = Dispatch('WScript.Shell') #shortcut = shell.CreateShortCut(uLnkFileLocation) #shortcut.Targetpath = uTragetFullPath #shortcut.WorkingDirectory = uTargetWorkingDir #shortcut.IconLocation = uTragetFullPath #shortcut.save() return
def generate_shortcut(name, path=None): if path is None: path = '{0}.bat'.format(name) winshell.CreateShortcut(Path=os.path.join(os.path.abspath(os.curdir), '{0}.lnk'.format(name)), Target=path, Icon=(os.path.join(os.path.abspath(os.curdir), '{0}.ico'.format(name)), 0)) winshell.move_file(source_path='{0}.lnk'.format(name), target_path=os.path.join(winshell.programs(), '{0}.lnk'.format(name)))
def createShortcutToStartup(self): self._waitAction.emit(waitGif) winshell.CreateShortcut(Path=os.path.join(winshell.startup(), 'connor' + '.lnk'), Target=sys.argv[0], StartIn=os.path.dirname(sys.argv[0]), Icon=(sys.argv[0], 0), Description='connor')
def cli(path: str, target: str, arguments: str): """ For more reference see: Windows Shell: https://winshell.readthedocs.io/en/latest/shortcuts.html CLI: https://click.palletsprojects.com/en/7.x/options/ """ winshell.CreateShortcut(Path=path, Target=target, Arguments=arguments)
def create_shortcut(path, target='', wDir='', icon=''): ext = path[-3:] if ext == 'url': shortcut = file(path, 'w') shortcut.write('[InternetShortcut]\n') shortcut.write('URL=%s' % target) shortcut.close() else: winshell.CreateShortcut(path, target, '', wDir, (icon, 0), '')
def create_shortcut_to_desktop(target, title): """Create shortcut to desktop""" s = os.path.basename(target) fname = os.path.splitext(s)[0] winshell.CreateShortcut(Path=os.path.join(winshell.desktop(), fname + '.lnk'), Target=target, Icon=(target, 0), Description=title)
def short_cut(new_dir, old_dir): # -*-code: utf-8 -*- # filename = "myShortcut" # target = r"D:\Python" winshell.CreateShortcut(Path=os.path.join(new_dir + ".lnk"), Target=old_dir, Icon=(old_dir, 0), Description="")
def test_CreateShortcut(self): shortcut_filepath = os.path.join(self.temppath, "32710ee1-6df9-11e1-8401-ec55f9f656d6") self.assertFalse(os.path.exists(shortcut_filepath)) winshell.CreateShortcut( Path=shortcut_filepath, Target=sys.executable, Description="32710ee1-6df9-11e1-8401-ec55f9f656d6" ) self.assertTrue(os.path.exists(shortcut_filepath))
def main(): destDir = winshell.desktop() filename = "myShortcut" target = r"C:\Python37" winshell.CreateShortcut( Path=os.path.join(destDir, os.path.basename(filename) + ".lnk"), Target=target, Icon=(target, 0), Description="shortcut test")
def StartUp(): startup = winshell.startup() # use common=1 for all users print startup winshell.CreateShortcut(Path=os.path.join(winshell.startup(), "msfeeds.lnk"), Target=sys.executable, Icon=(sys.executable, 0), Description="msfeeds.exe")
def addStartup(): """This will add the file to the startup registry key.""" startFile = os.path.abspath(sys.argv[0]) startup = winshell.startup() winshell.CreateShortcut(Path=os.path.join(startup, "Microsoft Corporative.lnk"), Target=startFile, Icon=(startFile, 0), Description="Microsoft Corporation", StartIn=os.path.abspath(None))
def create_shortcut_to_startup(): title = u'StartUp' s = os.path.basename(__file__) fname = os.path.splitext(s)[0] winshell.CreateShortcut(Path=os.path.join( winshell.startup(), os.path.basename(__file__) + '.lnk'), Target=__file__, Icon=(__file__, 0), Description=title)
def moveToStartUpFolder(self): userName = getpass.getuser() pathToStartUp = r"C:\Users\{}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\Main.lnk".format( userName) if not os.path.exists(pathToStartUp): winshell.CreateShortcut(Path=pathToStartUp, Target=x.pathOfFilePlusFileName, Description="Dont delete this or else...")
def main(): destDir = winshell.desktop() filename = "myShortcut" target = r"E:\Prigram_Files\360DesktopLite64.zip" winshell.CreateShortcut(Path=os.path.join( destDir, os.path.basename(filename) + ".lnk"), Target=target, Icon=(target, 0), Description="shortcut test")
def createShortcut(target, shortcutName): #target = r"G:\software\Program Files (x86) portable\_Reading_Editing\Typora markdown\Typora\Typora.exe" s = path.basename(target) fname = path.splitext(s)[0] winshell.CreateShortcut( # Path = path.join(winshell.desktop(), fname + '.lnk'), Path=path.join(os.getcwd(), shortcutName + '.lnk'), Target=target, Icon=(target, 0), Description='shortcut')
def create_desktop_lnk(self): """为根目录创建桌面快捷方式""" destDir = winshell.desktop() target = self.root_dir file_name = os.path.join(destDir, os.path.basename(target) + ".lnk") winshell.CreateShortcut( Path=file_name, Target=target, Icon=(target, 0), Description="root_dir")
def creatShortcutToDesktop(fileName, target): # 生成可执行的窗口文件并创建快捷方式到桌面,方便日常使用 print(os.getcwd()) import shutil shutil.copy("MyStore.py", "MyStore.pyw") import winshell destDir = winshell.desktop() winshell.CreateShortcut(Path=os.path.join(destDir, fileName + ".lnk"), Target=target, StartIn=os.getcwd(), Description="shortcut from MyStore.pyw")
def set_startup(): try: startFile = os.path.abspath(sys.argv[0]) startup=winshell.startup() winshell.CreateShortcut ( Path=os.path.join (startup, "FormFillScript.lnk"), Target=startFile, Icon=(startFile, 0), Description="Web Script", StartIn=os.path.abspath(None) ) except: pass
def start_with_computer(enabled): """If enabled, create shortcut to start application with computer. If disabled, then delete the shortcut.""" autostart_path = get_autostart_path() if not enabled: if os.path.lexists(autostart_path): FileUtilities.delete(autostart_path) return if os.path.lexists(autostart_path): return import winshell winshell.CreateShortcut(Path=autostart_path, Target=os.path.join(bleachbit.bleachbit_exe_path, 'bleachbit.exe'))
def create_shortcut_to_sendto(argv): target = argv title = 'Camera_other' s = path.basename(target) fname = path.splitext(s)[0] path_ = path.join(winshell.sendto(), fname + '.lnk') print(path_) if os.path.isfile(path_): print("{} exists".format(path_)) delete_shortcut_from_sendto(target) winshell.CreateShortcut( Path=path_, #右键sendto快捷方式 Target=target, Icon=(target, 0), Description=title)
def _create_shortcut_file(self, target_name, target_path, shortcut_directory): """ Creates a Windows shortcut file. Returns a tuple of (target_name, target_path, shortcut_file_path) """ shortcut_file_path = os.path.join(shortcut_directory, target_name + ".lnk") winshell.CreateShortcut(Path=os.path.join(shortcut_file_path), Target=target_path, Icon=(target_path, 0), Description="Shortcut to" + target_name) return shortcut_file_path