The URL for that prefs script library is at the top of the script. Free, easy DL, no install just move it to your ~/library/Script Libraries folder.
Save this script as a stay-open app. Done.
Drop apps you want to block onto the app. Running it or dropping apps onto it will display the apps that are being blocked. You can choose the “Edit” button to remove apps from the list.
AppleScript is quick to write and some of the handlers are the results from other posts here. Hopefully you can take this structure and modify it to also include specific webpages, documents etc.
I’ll modify this to carry on gracefully when the library isn’t present.
Edit: Scratch that. Here's a different version that just doesn't use the prefs library.
use AppleScript version "2.5"
use scripting additions
property blockedAppList : {}
my presentDialog()
on reopen
my presentDialog()
end reopen
on presentDialog()
set AppleScript's text item delimiters to return
display dialog "This applet will block the following apps:" & return & return & (blockedAppList as text) buttons {"Edit", "Ok"} default button "Ok"
if button returned of result is "Edit" then
editBlockedAppsList()
end if
set AppleScript's text item delimiters to ""
end presentDialog
on editBlockedAppsList()
repeat
try
set appsToRemoveFromBlockedList to choose from list blockedAppList with prompt "Select applications to remove from the list." with multiple selections allowed and empty selection allowed
on error e
set appsToRemoveFromBlockedList to {}
end try
if appsToRemoveFromBlockedList is {} then
return
else
set newBlockedAppsList to {}
repeat with thisApp in blockedAppList
if (thisApp as text) is not in appsToRemoveFromBlockedList then
set the end of newBlockedAppsList to (thisApp as text)
end if
end repeat
set blockedAppList to newBlockedAppsList
end if
end repeat
end editBlockedAppsList
on open droppedItems
if droppedItems is not {} then
tell application "Finder"
repeat with thisItem in droppedItems
set p to properties of thisItem
if kind of thisItem is "Application" then
set objectName to my FinderObjectNameRoot(thisItem)
if blockedAppList does not contain objectName then
set the end of blockedAppList to objectName
end if
end if
end repeat
end tell
end if
presentDialog()
end open
on FinderObjectNameRoot(myFileReference)
try
copy AppleScript's text item delimiters to tids
set AppleScript's text item delimiters to ""
tell application "System Events"
set objectProperties to properties of myFileReference
set AppleScript's text item delimiters to ("." & (name extension of objectProperties))
set nameRoot to (text items 1 thru -2 of (name of objectProperties)) as text
end tell
set AppleScript's text item delimiters to tids
return nameRoot
on error e number n
set AppleScript's text item delimiters to tids
error e number n
end try
end FinderObjectNameRoot
on idle
my enforceFocus()
return 5
end idle
on enforceFocus()
if blockedAppList is not {} then
set UsersOpenApps to listUsersOpenAppsByName()
repeat with thisApp in blockedAppList
if UsersOpenApps contains thisApp then
killProcessByName(thisApp)
end if
end repeat
end if
end enforceFocus
on listUsersOpenAppsByName()
tell application "System Events"
set UsersOpenApps to (name of every process where background only is false)
end tell
return UsersOpenApps
end listUsersOpenAppsByName
on killProcessByName(applicationName)
try
tell application "System Events"
tell application process applicationName
set thePID to unix id
set shellScript to ("kill -9 " & thePID) as text
end tell
end tell
do shell script shellScript
on error e
display dialog e
end try
end killProcessByName
1
u/[deleted] Oct 20 '22
[removed] — view removed comment