From 7c361a31ab43797507e9a0e250f799e1cea3eec9 Mon Sep 17 00:00:00 2001 From: AlexGadd Date: Sat, 25 Oct 2025 09:13:34 +1300 Subject: [PATCH 1/2] 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 --- commands/system/paste-clipboard.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/system/paste-clipboard.sh b/commands/system/paste-clipboard.sh index b2b738d0d..190296318 100755 --- a/commands/system/paste-clipboard.sh +++ b/commands/system/paste-clipboard.sh @@ -15,6 +15,7 @@ # @raycast.authorURL https://raycast.com/AlexGadd osascript -e 'set clipboardContent to the clipboard' \ +-e 'delay 0.2' \ -e 'set charCount to count of characters of clipboardContent' \ -e 'tell application "System Events"' \ -e ' repeat with i from 1 to charCount' \ From 279aa339d3a2377c69ffda0118b0856125037548 Mon Sep 17 00:00:00 2001 From: AlexGadd Date: Thu, 30 Oct 2025 19:04:17 +1300 Subject: [PATCH 2/2] 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 --- commands/system/paste-clipboard.sh | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/commands/system/paste-clipboard.sh b/commands/system/paste-clipboard.sh index 190296318..40a8922a0 100755 --- a/commands/system/paste-clipboard.sh +++ b/commands/system/paste-clipboard.sh @@ -14,8 +14,30 @@ # @raycast.author AlexGadd # @raycast.authorURL https://raycast.com/AlexGadd +sleep 0.3 +#returns "true" or "false" if key is held down +commandKeyDown=$(osascript -l JavaScript -e "ObjC.import('Cocoa'); ($.NSEvent.modifierFlags & $.NSEventModifierFlagCommand) > 1") +controlKeyDown=$(osascript -l JavaScript -e "ObjC.import('Cocoa'); ($.NSEvent.modifierFlags & $.NSEventModifierFlagControl) > 1") +optionKeyDown=$(osascript -l JavaScript -e "ObjC.import('Cocoa'); ($.NSEvent.modifierFlags & $.NSEventModifierFlagOption) > 1") +shiftKeyDown=$(osascript -l JavaScript -e "ObjC.import('Cocoa'); ($.NSEvent.modifierFlags & $.NSEventModifierFlagShift) > 1") +functionKeyDown=$(osascript -l JavaScript -e "ObjC.import('Cocoa'); ($.NSEvent.modifierFlags & $.NSEventModifierFlagFunction) > 1") + +keys=("$commandKeyDown" "$controlKeyDown" "$optionKeyDown" "$shiftKeyDown" "$functionKeyDown") + +anyPressed=false +for key in "${keys[@]}"; do + if [[ $key == "true" ]]; then + anyPressed=true + break + fi +done + +if $anyPressed; then +osascript -e 'set theAlertText to "Modifier key held"' \ +-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"' \ +-e 'display alert theAlertText message theAlertMessage as critical buttons {"OK"} default button "OK"' \ +else osascript -e 'set clipboardContent to the clipboard' \ --e 'delay 0.2' \ -e 'set charCount to count of characters of clipboardContent' \ -e 'tell application "System Events"' \ -e ' repeat with i from 1 to charCount' \ @@ -23,3 +45,4 @@ osascript -e 'set clipboardContent to the clipboard' \ -e ' keystroke theChar' \ -e ' end repeat' \ -e 'end tell' +fi