Skip to content

Commit

Permalink
增加查询 ip、运行命令、查看磁盘使用情况的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
wxnacy committed May 31, 2020
1 parent 4db6154 commit f30c1c3
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 10 deletions.
Binary file added 0FA3CA6F-AB00-446F-95B9-EAB309AA7AD4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 29615B9D-6FED-426D-AC5D-34E5D09C8770.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 679ACFD3-4EFD-4253-8DE7-43596D7AE00B.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 92606F4B-F131-40B2-AB3B-BE0A56339FA8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

提供查看帮助文档、复制常用命令等功能

[Download](https://github.com/wxnacy/alfred-commands-workflow/releases/download/v2020.05.23/Commands.Help.Tools.alfredworkflow)
[Download](https://github.com/wxnacy/alfred-commands-workflow/releases/download/v2020.06.01/Commands.Help.Tools.alfredworkflow)

## 复制常用命令

Expand All @@ -18,3 +18,14 @@

![dl](https://github.com/wxnacy/image/blob/master/blog/alfred-dl.gif)

## 查询 ip

![t3W2RS.gif](https://s1.ax1x.com/2020/06/01/t3W2RS.gif)

## 运行命令

![t3R2u9.gif](https://s1.ax1x.com/2020/06/01/t3R2u9.gif)

# 查看磁盘使用情况

![t3WzZR.gif](https://s1.ax1x.com/2020/06/01/t3WzZR.gif)
105 changes: 105 additions & 0 deletions convert_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author: wxnacy([email protected])
# Description:

import sys
import json
import os
import logging
import subprocess

from workflow import Workflow3
from workflow import web
import time
from datetime import datetime
from datetime import timedelta
from pytz import timezone
from pytz import utc


def input_type(text):
'''判断输入类型'''
try:
int(text)
return int
except ValueError:
pass

return str

def now():
'''获取当前时间'''
ts = int(time.time())
return format_timestamp(ts)

def fmt_dt(dt):
return dt.strftime("%Y-%m-%d %H:%M:%S")

def format_timestamp(ts):
'''格式化时间戳'''
res = dict(timestamp = ts)
# t = datetime.fromtimestamp(ts)
t = datetime.utcfromtimestamp(ts)
res['local'] = fmt_dt(datetime.now())
# t = t.replace(tzinfo=timezone("UTC"))

for i in list(range(-12, 13)):
dt = t + timedelta(hours=i)
res[i] = fmt_dt(dt)

return res

def output_result(wf, res):
'''格式化输出'''
item = dict(valid = True)
item['title'] = res['timestamp']
item['subtitle'] = '时间戳'
item['arg'] = item['title']
wf.add_item(**item)

for k, v in res.items():
item['title'] = v
if k == 'local':
item['subtitle'] = '本地时间'
item['arg'] = item['title']
wf.add_item(**item)
elif k == 0:
item['subtitle'] = 'UTC 时间'
item['arg'] = item['title']
wf.add_item(**item)
elif k == -4:
item['subtitle'] = '纽约时间'
item['arg'] = item['title']
wf.add_item(**item)

def main(wf):
args = wf.args
logging.info(args)
t = args[0]

whole_input = ' '.join(args)

type = input_type(t)
if type == int:
res = format_timestamp(int(t))
output_result(wf, res)


item = dict(valid = True)
if t == 'now':
res = now()
output_result(wf, res)

logging.info(list(filter(lambda o: 'item' in o, dir(wf))))
logging.info(wf._items)
if not wf._items:
wf.add_item(title="输入需要转换的时间", subtitle = ' '.join(args))

wf.send_feedback()


if __name__ == '__main__':
wf = Workflow3()
sys.exit(wf.run(main))

19 changes: 19 additions & 0 deletions df.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Author: wxnacy([email protected])
# Description:

disk=`df -h | grep 'disk.*System'`
disks=(${disk})
VOLUME=$(system_profiler SPSoftwareDataType | grep 'Boot Volume' | awk '{print substr($0, index($0,$3))}')

subtitle="Size: ${disks[1]} Used: ${disks[2]} Avail: ${disks[3]}"

cat << EOB
<?xml version="1.0"?>
<items>
<item uid="" arg="${subtitle}">
<title>${VOLUME}</title>
<subtitle>${subtitle}</subtitle>
</item>
</items>
EOB
159 changes: 150 additions & 9 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
<false/>
</dict>
</array>
<key>29615B9D-6FED-426D-AC5D-34E5D09C8770</key>
<array>
<dict>
<key>destinationuid</key>
<string>2CE54DD1-24E6-4356-BFCA-AB8E6F825958</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>2CE54DD1-24E6-4356-BFCA-AB8E6F825958</key>
<array>
<dict>
Expand All @@ -34,6 +47,19 @@
</array>
<key>3E407FFE-9A3F-49F5-B15F-CE97FAFAED07</key>
<array/>
<key>679ACFD3-4EFD-4253-8DE7-43596D7AE00B</key>
<array>
<dict>
<key>destinationuid</key>
<string>2CE54DD1-24E6-4356-BFCA-AB8E6F825958</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>71463E91-2E01-41CC-B10F-3A01857AB2DE</key>
<array>
<dict>
Expand Down Expand Up @@ -333,6 +359,104 @@
<key>version</key>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<true/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>0</integer>
<key>escaping</key>
<integer>0</integer>
<key>keyword</key>
<string>time</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string>正在处理,请稍后</string>
<key>script</key>
<string>python convert_time.py $1</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>请输入要转换的时间</string>
<key>title</key>
<string>对时间进行转换</string>
<key>type</key>
<integer>0</integer>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>679ACFD3-4EFD-4253-8DE7-43596D7AE00B</string>
<key>version</key>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<true/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>2</integer>
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>disk</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string>正在查询,请稍后</string>
<key>script</key>
<string>./df.sh</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string></string>
<key>title</key>
<string>查看硬盘空间</string>
<key>type</key>
<integer>0</integer>
<key>withspace</key>
<false/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>29615B9D-6FED-426D-AC5D-34E5D09C8770</string>
<key>version</key>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand All @@ -341,7 +465,10 @@
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>echo -n `$1`</string>
<string>$@ | while read line
do
echo $line
done</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
Expand Down Expand Up @@ -544,7 +671,14 @@ echo -n $(nohup curl $1 -O &amp;)</string>
<key>xpos</key>
<integer>180</integer>
<key>ypos</key>
<integer>425</integer>
<integer>685</integer>
</dict>
<key>29615B9D-6FED-426D-AC5D-34E5D09C8770</key>
<dict>
<key>xpos</key>
<integer>180</integer>
<key>ypos</key>
<integer>555</integer>
</dict>
<key>2CE54DD1-24E6-4356-BFCA-AB8E6F825958</key>
<dict>
Expand All @@ -558,7 +692,7 @@ echo -n $(nohup curl $1 -O &amp;)</string>
<key>xpos</key>
<integer>510</integer>
<key>ypos</key>
<integer>705</integer>
<integer>965</integer>
</dict>
<key>5348461E-968E-4C7D-A961-2C53A47EEB39</key>
<dict>
Expand All @@ -567,12 +701,19 @@ echo -n $(nohup curl $1 -O &amp;)</string>
<key>ypos</key>
<integer>170</integer>
</dict>
<key>679ACFD3-4EFD-4253-8DE7-43596D7AE00B</key>
<dict>
<key>xpos</key>
<integer>180</integer>
<key>ypos</key>
<integer>430</integer>
</dict>
<key>71463E91-2E01-41CC-B10F-3A01857AB2DE</key>
<dict>
<key>xpos</key>
<integer>180</integer>
<key>ypos</key>
<integer>705</integer>
<integer>965</integer>
</dict>
<key>7550C092-A6C8-4BB2-A593-865B5A9F831B</key>
<dict>
Expand Down Expand Up @@ -600,35 +741,35 @@ echo -n $(nohup curl $1 -O &amp;)</string>
<key>xpos</key>
<integer>180</integer>
<key>ypos</key>
<integer>570</integer>
<integer>830</integer>
</dict>
<key>ABFDAC0A-59AC-46FF-8317-30A5EE1E72B4</key>
<dict>
<key>xpos</key>
<integer>350</integer>
<key>ypos</key>
<integer>570</integer>
<integer>830</integer>
</dict>
<key>AEEE997C-352F-4019-BFEF-40480C5770E9</key>
<dict>
<key>xpos</key>
<integer>350</integer>
<key>ypos</key>
<integer>425</integer>
<integer>685</integer>
</dict>
<key>C2C22059-F577-4982-B0BF-665E0E358013</key>
<dict>
<key>xpos</key>
<integer>565</integer>
<key>ypos</key>
<integer>425</integer>
<integer>685</integer>
</dict>
<key>F800D030-BFC4-490B-813D-74D375AA6EF0</key>
<dict>
<key>xpos</key>
<integer>350</integer>
<key>ypos</key>
<integer>705</integer>
<integer>965</integer>
</dict>
</dict>
<key>variablesdontexport</key>
Expand Down
Loading

0 comments on commit f30c1c3

Please sign in to comment.