Page 1 of 1

Quote IDE Tool

Posted: Sat Feb 01, 2025 7:09 am
by Piero
PB IDE Tool (AppleScript) to quote current word (+ spaces) or selection
Note: you must run the "applet" inside the AppleScript app (use right-click/"show package contents")
You can "copy applet as Pathname" by right-clicking it keeping the option key down…

Edit: updated to place a quote at cursor position, added a comment to show how you can get it
Edit2: fixed for Sequoia 15.6.1

Code: Select all

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

-- wait for no modifier key pressed (shortcut)
use framework "AppKit" -- for NSEvent
repeat while (((current application's NSEvent's modifierFlags()) div ¬
	(current application's NSShiftKeyMask as integer)) mod 2) > 0 or ¬
	(((current application's NSEvent's modifierFlags()) div ¬
		(current application's NSControlKeyMask as integer)) mod 2) > 0 or ¬
	(((current application's NSEvent's modifierFlags()) div ¬
		(current application's NSAlternateKeyMask as integer)) mod 2) > 0 or ¬
	(((current application's NSEvent's modifierFlags()) div ¬
		(current application's NSCommandKeyMask as integer)) mod 2) > 0
end repeat

tell application "PureBasic" to activate -- just in case
tell application "System Events"
	tell application process "PureBasic" to key code 53 -- press esc
	set sel to count ((value of attribute "AXSelectedText" of text area 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of window 1 of application process "PureBasic") as string)
	--set c1 to item 2 of ((value of attribute "AXSelectedTextRange" of text area 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of window 1 of application process "PureBasic") as list)
	if sel is 0 then
		tell application process "PureBasic" to key code 123 using {control down, shift down}
		set sel to count ((value of attribute "AXSelectedText" of text area 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of window 1 of application process "PureBasic") as string)
	end if
	tell application process "PureBasic" to key code 123
	tell application process "PureBasic" to keystroke "\""
	repeat sel times
		tell application process "PureBasic" to key code 124
	end repeat
	tell application process "PureBasic" to keystroke "\""
end tell
keystroke can be used to type text, like
keystroke "[/code]"
keystroke "Hello WΩrƒd"
or for shortcuts (same for key code):
keystroke "a" using {shift down, option down, command down}

Re: Quote IDE Tool

Posted: Sun Sep 14, 2025 7:01 am
by Piero
Fixed for Sequoia 15.6.1; hope apple will also "revert" the problems (e.g., with "a reference to" UI elements)