Skip to content

Instantly share code, notes, and snippets.

@ChristoferK
ChristoferK / Safari#Filter Tabs By URL.applescript
Created Oct 13, 2020
[Match Safari Tabs Against URL Substring] A fast, efficient tab filter that operates over all tabs in all Safari windows to return a reference to those where the URL contains a given phrase. #AppleScript #Safari #browser #windows #tabs #URL #filter #search
View Safari#Filter Tabs By URL.applescript
on SafariTabsWhoseURLsContain:(phrase as text)
set text item delimiters to linefeed
tell application id "com.apple.Safari" to if it ¬
is running then tell every window to if ¬
it exists then tell (it where (index of ¬
tab 1 where phrase is in the URL) is in ¬
index of tabs) to tell (every tab whose ¬
URL contains the phrase) to if (exists) ¬
then return a reference to it
end SafariTabsWhoseURLsContain:
@ChristoferK
ChristoferK / Chrome#(Re)Store URLs.applescript
Created Nov 15, 2019
[(Re)Store Chrome Tabs] Stores a list of open Chrome URLs, writing out to file and preserving arrangement; restores from file. #AppleScript #Chrome #Chromium #tabs #URLs #save #restore
View Chrome#(Re)Store URLs.applescript
property home : system attribute "HOME"
property file : home & "/.chrometabs"
on storeURLs()
close access (open for access my file)
tell application id "com.google.chrome" to ¬
set URLs to every window's tabs's URL
write the URLs to my file
@ChristoferK
ChristoferK / Discretionary URL Open vs Activate Existing Tab.applescript
Last active Oct 3, 2019
[If URL Open, Then: Activate Tab; Else: Open URL] A discerning URL opener for any Chromium-based web browser that eliminates the need for iteration. #AppleScript #Chromium #Open #URL #browser #Chrome #Brave
View Discretionary URL Open vs Activate Existing Tab.applescript
to open location www
--OR: application id "com.google.Chrome"
tell application id "com.brave.Browser" to tell windows to tell (it ¬
where integer 1 in ((tab 1's id where www is in URL) & 0) ¬
is in the id of every tab) & false to tell the first item
if it = false then return continue open location www
set i to character id (id of tab 1 where www is in URL)
set t to character id (id of tabs)
set the active tab index to the offset of i in t
activate
@ChristoferK
ChristoferK / Get The Front Document's Containing Folder.applescript
Last active Sep 29, 2019
[Front Document's Containing Folder] Retrieves, if available, the path to the frontmost application's active document, from which the parent folder is returned #AppleScript #document #path #file #folder #Accessibility #SystemEvents
View Get The Front Document's Containing Folder.applescript
tell application id "com.apple.systemevents" to tell (the first process ¬
where it is frontmost) to tell (a reference to the front window) ¬
to if it exists then tell its attribute "AXDocument"'s value to ¬
if it is not in [missing value, "file:///Irrelevent"] then ¬
return my (POSIXPathOfFolder for it)
false
on POSIXPathOfFolder for (fileURL as text)
local fileURL
@ChristoferK
ChristoferK / Create Machine Device Icon (High Sierra).applescript
Last active Mar 7, 2021
[Machine Device Icon] Returns a path to a PNG image file containing a hi-resolution representation of the user's machine #AppleScript #AppleScriptObjC #device #computer #machine #icon #NSWorkspace #PNG
View Create Machine Device Icon (High Sierra).applescript
use framework "Foundation"
use framework "AppKit"
use scripting additions
property this : a reference to the current application
property nil : a reference to missing value
property _1 : a reference to reference
property NSWorkspace : a reference to NSWorkspace of this
@ChristoferK
ChristoferK / Script Editor#Default Selected Tab.applescript
Last active Jan 9, 2020
[Script Editor#Default Selected Tab] Sets Script Editor's `Replies` pane as the default selected tab #AppleScript #defaults #ScriptEditor #SystemEvents #propertylist
View Script Editor#Default Selected Tab.applescript
set fp to "~/Library/Preferences/com.apple.ScriptEditor2.plist"
tell application id "com.apple.SystemEvents" to tell the ¬
property list file fp to make new property list item ¬
with properties {name:"ScriptWindowState", value
{selectedTab:"log"}}
@ChristoferK
ChristoferK / [JSObjC] Get Classes List.js
Last active May 19, 2019
[Objective-C Classes List] Retrieves an ordered, filtered list of Objective-C NSObject subclasses and writes them to file. #JXA #JavaScript #ObjectiveC #ObjC #classes #objc_copyClassList
View [JSObjC] Get Classes List.js
ObjC.import('stdlib');
ObjC.import('Foundation');
__NSString__ = $.NSString.stringWithString.bind($.NSString);
ObjC.bindFunction('objc_copyClassList', ['void**', ['int']]);
ObjC.bindFunction('class_getName', ['char *', ['void*']]);
ObjC.bindFunction('class_getSuperclass', ['void*', ['void*']]);
ObjC.bindFunction('class_isMetaClass', ['bool *', ['void*']]);
i = 0; // Counter variable
@ChristoferK
ChristoferK / Centre Window.applescript
Last active Apr 29, 2020
[Centre Window on Screen] Centres the frontmost window on screen #AppleScript #SystemEvents #UI #window #position
View Centre Window.applescript
use application "System Events"
property process : a reference to (first process whose frontmost = true)
property window : a reference to front window of my process
property display : a reference to scroll area 1 of process "Finder"
if not (my window exists) then return
set [width, height] to size of my window
set [screenX, screenY] to size of my display
@ChristoferK
ChristoferK / Scriptable Applications.applescript
Last active Mar 7, 2021
[Scriptable Apps] Retrieves a list of bundle identifiers for the applications in the /Applications folder (and sub-folders) that are Applescriptable. #AppleScript #applications #scriptable #Finder
View Scriptable Applications.applescript
property dir : path to applications folder
use Finder : application id "com.apple.Finder"
property contents : a reference to (folder dir)'s entire contents
property list : a reference to application files in its contents
script
property parent : my list
property id : my id
property key : my has scripting terminology
@ChristoferK
ChristoferK / Chromium#Close Other Tabs.applescript
Last active Mar 14, 2020
[Close Every Other Tab In All Browser Windows] A pair of scripts that close every other tab in all windows of a Chromium-based browser or Safari, leaving the currently active tab open by itself. #AppleScript #browser #Chromium #Chrome #Brave #Safari #close #tabs
View Chromium#Close Other Tabs.applescript
--OR: tell app id "com.google.Chrome"
tell application id "com.brave.browser" to if it is ¬
running then tell every window to if (exists) ¬
then close (the tabs whose id my window 1's ¬
active tab's id)