Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions commands/system/paste-clipboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@
# @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 'set charCount to count of characters of clipboardContent' \
-e 'tell application "System Events"' \
Expand All @@ -22,3 +45,4 @@ osascript -e 'set clipboardContent to the clipboard' \
-e ' keystroke theChar' \
-e ' end repeat' \
-e 'end tell'
fi