Repository navigation
Expand file tree
/
Copy pathKeystroker.sh
More file actions
51 lines (51 loc) · 1.48 KB
/
Copy pathKeystroker.sh
File metadata and controls
51 lines (51 loc) · 1.48 KB
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
47
48
49
50
51
#!/bin/bash
# License: The MIT License (MIT)
# Author Zuzzuc https://github.com/Zuzzuc/
#
# Supported modes: "keystroke" and "cp"
# keystroke simulates keystrokes, this is very fast when performing shorter words or letters.
# cp works by, instead of parsing the the word letter by letter as keystroke does, parsing the whole word at once. This is much faster if the provided keystrokes are longen than 10 words.
#
default="e"
defaultsleep="5"
defaultmode="keystroke"
if [[ "$1" -le "0" ]];then
echo '$1 needs to be greater than 0'
exit 1
fi
if [[ "$2" == "" ]];then
keystroke=e
echo "Keystroke(s) not specified, using default($default)"
else
keystroke=$2
echo "Keystroke set to $keystroke"
fi
if [[ "$3" == "" ]];then
sleep=$defaultsleep
else
sleep=$3
fi
if [[ "$4" == "cp" ]];then
mode="cp"
elif [[ "$4" == "keystroke" ]];then
mode="keystroke"
else
echo "Did not recognize mode, using default($defaultmode)"
mode=$defaultmode
fi
backupcopy=$(pbpaste)
echo "Launching in $sleep second(s) with mode $mode"
sleep $sleep
echo "launching"
if [ "$mode" == "keystroke" ];then
osascript -e 'repeat "'$1'" times' -e 'tell application "System Events"' -e "keystroke \"$keystroke\"" -e 'keystroke return' -e 'end tell' -e 'end repeat'
elif [ "$mode" == "cp" ];then
echo "$keystroke" | pbcopy
c=0
while [ "$c" -le "$1" ];do
osascript -e 'tell application "System Events"' -e 'keystroke "v" using {command down}' -e 'keystroke return' -e 'end tell'
let c=c+1;
done
fi
echo "$backupcopy" | pbcopy
echo "Done."