Skip to content

Commit 89163d6

Browse files
authored
Added delay to paste (#1007)
* Added delay to paste If keys are still held down while it starts typing this can trigger commands or alternative characters to be typed, may need to add a description to warn people if they don't understand how this script works? Not sure if that's standard practice for these commits * Added alert window and modifier key check Returns an alert window to tell the person not to hold modifier keys while the script runs, also added a brief pause before it runs to allow them to release the keys
1 parent 0b49ddc commit 89163d6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

commands/system/paste-clipboard.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@
1414
# @raycast.author AlexGadd
1515
# @raycast.authorURL https://raycast.com/AlexGadd
1616

17+
sleep 0.3
18+
#returns "true" or "false" if key is held down
19+
commandKeyDown=$(osascript -l JavaScript -e "ObjC.import('Cocoa'); ($.NSEvent.modifierFlags & $.NSEventModifierFlagCommand) > 1")
20+
controlKeyDown=$(osascript -l JavaScript -e "ObjC.import('Cocoa'); ($.NSEvent.modifierFlags & $.NSEventModifierFlagControl) > 1")
21+
optionKeyDown=$(osascript -l JavaScript -e "ObjC.import('Cocoa'); ($.NSEvent.modifierFlags & $.NSEventModifierFlagOption) > 1")
22+
shiftKeyDown=$(osascript -l JavaScript -e "ObjC.import('Cocoa'); ($.NSEvent.modifierFlags & $.NSEventModifierFlagShift) > 1")
23+
functionKeyDown=$(osascript -l JavaScript -e "ObjC.import('Cocoa'); ($.NSEvent.modifierFlags & $.NSEventModifierFlagFunction) > 1")
24+
25+
keys=("$commandKeyDown" "$controlKeyDown" "$optionKeyDown" "$shiftKeyDown" "$functionKeyDown")
26+
27+
anyPressed=false
28+
for key in "${keys[@]}"; do
29+
if [[ $key == "true" ]]; then
30+
anyPressed=true
31+
break
32+
fi
33+
done
34+
35+
if $anyPressed; then
36+
osascript -e 'set theAlertText to "Modifier key held"' \
37+
-e 'set theAlertMessage to "To allow this script to function, please ensure you do not hold any modifier keys down while the paste script runs"' \
38+
-e 'display alert theAlertText message theAlertMessage as critical buttons {"OK"} default button "OK"' \
39+
else
1740
osascript -e 'set clipboardContent to the clipboard' \
1841
-e 'set charCount to count of characters of clipboardContent' \
1942
-e 'tell application "System Events"' \
@@ -22,3 +45,4 @@ osascript -e 'set clipboardContent to the clipboard' \
2245
-e ' keystroke theChar' \
2346
-e ' end repeat' \
2447
-e 'end tell'
48+
fi

0 commit comments

Comments
 (0)