forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlowercase.py
executable file
·46 lines (37 loc) · 1.03 KB
/
lowercase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Lowercase
# @raycast.mode inline
# @raycast.packageName Change Case
# Optional parameters:
# @raycast.icon ./images/lowercase-light.png
# @raycast.iconDark ./images/lowercase-dark.png
# Documentation:
# @raycast.author Robert Cooper
# @raycast.authorURL https://github.com/robertcoopercode
# @raycast.description Change clipboard text to lowercase
import subprocess
def getClipboardData():
p = subprocess.Popen(["pbpaste"], stdout=subprocess.PIPE)
data = p.stdout.read()
return tryDecode(data)
def setClipboardData(data):
p = subprocess.Popen(["pbcopy"], stdin=subprocess.PIPE)
p.stdin.write(tryEncode(data))
p.stdin.close()
def tryDecode(s):
try:
return s.decode('utf-8')
except:
return s
def tryEncode(s):
try:
return s.encode('utf-8')
except:
return s
clipboard = str(getClipboardData())
result = clipboard.lower()
setClipboardData(result)
print(result)