Quote IDE Tool

Mac OSX specific forum
User avatar
Piero
Addict
Addict
Posts: 918
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Quote IDE Tool

Post 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

Code: Select all

-- 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 scint to a reference to text area 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of splitter group 1 of item 1 of (windows of application process "PureBasic" whose name begins with "PureBasic")
	tell scint to set sel to count (value of attribute "AXSelectedText" as string)
	-- tell scint to set c1 to item 2 of (value of attribute "AXSelectedTextRange" as list) -- get cursor position
	if sel is 0 then
		tell application process "PureBasic" to key code 123 using {control down, shift down}
		tell scint to set sel to count (value of attribute "AXSelectedText" 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}