其它命令汇总

1.随机获取一张图片,可选择手机端还是pc端。

var https = require("https")

function loadPage(url) {
     

    var pm = new Promise(function(resolve, reject) {
     
        https.get(url, function(res) {
     
            var html = '';
            res.on('data', function(d) {
     
                html += d.toString()
            });
            res.on('end', function() {
     
                resolve(html);
            });
        }).on('error', function(e) {
     
            reject(e)
        });
    });
    return pm;
}

quickcommand.showSelectList(['PC', 'Mobile'])
    .then((x) => {
     
        var htmlurl = 'https://img.xjh.me/random_img.php?type=bg&ctype=nature&302&device=pc'
        if (x.id == 1) {
     
            htmlurl = 'https://img.xjh.me/random_img.php?type=bg&ctype=nature&302&device=mobile'
        }
        console.log(htmlurl)
        loadPage(htmlurl).then(function(d) {
     
            // console.log(d);
            var imgurl = 'https:' + quickcommand.htmlParse(d).querySelector('img').alt
            var idmpath = process.env['UtoolsCoreAssets'] + '/IDM/App/IDMan.exe'
            child_process.exec(`${
       idmpath} /d "${
       imgurl}"`)

            quickcommand.showMessageBox('解析成功!')
            quickcommand.setTimeout(() => {
     
                utools.outPlugin()
            }, 1500)
        });
    })

2.随机获取一个头像。

utools.setExpendHeight(100)
var imgurl = 'https://api.uomg.com/api/rand.avatar'
var idmpath = process.env['UtoolsCoreAssets'] + '/IDM/App/IDMan.exe'
child_process.exec(`${
       idmpath} /d "${
       imgurl}"`)

quickcommand.showMessageBox('解析成功!')
quickcommand.setTimeout(() => {
     
    utools.outPlugin()
}, 1500)

3.将程序添加到开机启动。
powershell脚本


$exePath = "{
     {MatchedFiles[0].path}}"
$exeFilename = [System.IO.Path]::GetFileNameWithoutExtension($exePath)
$linkFilename = $exeFilename + ".lnk"
$shell = New-Object -ComObject WScript.Shell
$startUpFolder = "$Env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup"

$shortcut = $shell.CreateShortcut("$startUpFolder/$linkFilename")
$shortcut.TargetPath = $exePath
$shortcut.IconLocation = "shell32.dll,23"
$shortcut.Save()

Write-Host "Success Add: " + $exeFilename

4.打开应用所在目录。

import os

app_fullpath = r'{
     {WindowInfo.appPath}}'
dir = os.path.dirname(app_fullpath)
os.startfile(dir)

5.移除当前目录或子目录指定文件。
powershell脚本
输入正则来删除文件


$pattern = Read-Host "输入正则"
$contain_child = Read-Host "is Recurse?1 yes 2 no"

function RemoveFile($obj,$is_recurse) {
     
    $fullname = $obj.FullName
    if($fullname -match $pattern){
     
    	if($is_recurse){
     
            Remove-Item $fullname -Recurse
        }
        else{
     
            Remove-Item $fullname
        }
        Write-Host "removed " + $fullname
    }
}

$dir = '{
     {WindowInfo.title}}'
Write-Host $dir
if($contain_child -eq "1"){
     
    Get-ChildItem -path $dir -Recurse | ForEach-Object {
     
        RemoveFile($_,$True)
    }
}
elseif($contain_child -eq "2") {
     
    Get-ChildItem -path $dir | ForEach-Object {
     
    	RemoveFile($_,$False)
    }
}

6.使用IDM下载。
指定使用idm进行下载,使用超级面板启动。

import os
import subprocess

url = r'{
     {input}}'
idm_path = os.environ['UtoolsCoreAssets'] + '/IDM/App/IDMan.exe'
subprocess.call([idm_path,'/d',url])

7.随机一键轮播视频。

import os
import json
import subprocess

mpc_path = '%s/%s' % (os.environ['UtoolsCoreAssets'],'MPC-HC/mpc-hc64.exe')
data_path = '%s/%s' % (os.environ['UtoolsCoreData'],'Data/Path.json')
with open(data_path,'r') as dat:
    lunbo_path = json.loads(dat.read())['lunbo']
    subprocess.call([mpc_path,lunbo_path,'/randomize','/fullscreen'])

你可能感兴趣的:(我的原创Utools工具集)