https://prismjs.com
Powerful Javascript!

Code: Select all
(* -- by Piero
PLEASE BE SURE TO READ BELOW FOR "INSTALLATION" INSTRUCTIONS.
This creates a "Loudmaxed" copy of dropped audio or video files.
Audio will be enhanced!
You can also choose files via dialog by running it (double click).
Multichannel (surround) sound will be made stereo.
If a video is multi-language/multi-audio, you can choose the right track to process.
If a video is subtitled, you can optionally keep one of the subtitles.
Copies are saved on the same folder of the original, and will be overwritten if you process the original again.
by Piero
Export this script as an application, after you opened it with Script Editor...
You can easily change the icon of the exported app:
https://support.apple.com/lv-lv/guide/mac-help/mchlp2313/mac
You need to download and "install" 3 free softwares (put into the finder window that will open when you run the "incomplete" version of this app).
You can also normally install LoudMax.vst into Library/Audio/Plug-Ins/VST/.
Works with Homebrew ffmpeg (/opt/homebrew/bin/ffmpeg) and mrswatson64 can be put into /opt/homebrew/bin/ too.
ffmpeg
https://www.osxexperts.net/ ( https://evermeet.cx/ffmpeg/ https://ffmpeg.org/ )
mrswatson64
https://github.com/teragonaudio/MrsWatson/blob/master/bin/Mac%20OS%20X/mrswatson64
LoudMax.vst
https://pluginguru.net/loudmax-for-mac/ ( https://loudmax.blogspot.com/ )
"standing on the shoulders of giants"...
*)
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
property outvol : "0.94" -- do not set volume to more than 0.94
property addtoname : "_LM"
on ex(ff) -- avoids applescript "exists" bug
try
do shell script "test -e " & ff
return true
on error
return false
end try
end ex
on notinst(sss, ooo)
tell application "Finder"
activate
open (((path to me) as text) & "Contents:Resources:") as alias
display dialog sss & " not installed!\n\nPlease drag into the Finder window that just opened!" & "\n\n\n" & ooo buttons ("OK") default button "OK"
end tell
end notinst
on updpr(stri, nu)
set progress description to stri
set progress completed steps to nu
delay 0.34
end updpr
on open thefiles
set tempfolder to path to temporary items
try
set ptm to quoted form of POSIX path of (path to me)
if not ex("/Library/Audio/Plug-Ins/VST/LoudMax.vst") then
if not ex(ptm & "Contents/Resources/LoudMax.vst") then
otinst("Loudmax", "...or into /Library/Audio/Plug-Ins/VST/\n\nhttps://loudmax.blogspot.com/")
return
end if
end if
set ffm to "/opt/homebrew/bin/ffmpeg"
if not ex(ffm) then set ffm to ptm & "Contents/Resources/ffmpeg"
if not ex(ffm) then
otinst("Ffmpeg", "...or install with homebrew (/opt/homebrew/bin/)\n\nhttps://www.osxexperts.net/\n\nhttps://ffmpeg.org/\n\nhttps://evermeet.cx/ffmpeg/")
return
end if
set mrs to "/opt/homebrew/bin/mrswatson64"
if not ex(mrs) then set mrs to ptm & "Contents/Resources/mrswatson64"
if not ex(mrs) then
notinst("mrswatson64", "https://github.com/teragonaudio/MrsWatson/blob/master/bin/Mac%20OS%20X/mrswatson64")
return
end if
set lmthre to word 1 of text returned of (display dialog "Loudmax Threshold\n\nExample: 0.02 will not enhance very low volumes\n\nSuggested values: from 0.0 to 0.5" buttons {"Cancel", "OK"} default button "OK" with icon caution default answer "0.0")
set filecount to count thefiles
set ii to 1
repeat with i in thefiles
set quotedinputfile to quoted form of POSIX path of i
set progress total steps to 4 --filecount
set progress additional description to "Processing File " & ii & " of " & filecount & ":\n\n" & quotedinputfile
updpr("Analyzing File Tracks...\n\nHold ⌘. to Stop.\n", 0)
set quotedtempfolder to quoted form of (POSIX path of tempfolder)
set tmpextractedpcm to quotedtempfolder & "lmaudioin.pcm"
set tmploudmaxedpcm to quotedtempfolder & "lmaudioout.pcm"
set filname to ((characters 1 thru -((offset of "." in (the reverse of (characters of (POSIX path of i))) as text) + 1) of (POSIX path of i)) as text) & addtoname
set quotfilname to quoted form of filname
set filext to ((characters -1 thru -((offset of "." in (the reverse of (characters of (POSIX path of i))) as text)) of (POSIX path of i)) as text)
set atr to "0"
set str to "0"
set sot to "1"
set trstr to "AUDIO TRACKS:" & return
set atrax to ""
try
set atrax to (do shell script ffm & " -i " & quotedinputfile & " 2>&1 | grep -E 'Stream.*Audio' | grep -En '.'") as string
end try
set trstr to trstr & atrax
set stra to ""
try
set stra to (do shell script ffm & " -i " & quotedinputfile & " 2>&1 | grep -E 'Stream.*Subtitle' | grep -En '.'") as string
set trstr to trstr & return & return & "SUBTITLE TRACKS:"
set trstr to trstr & return & stra
on error
set sot to "0"
end try
if ((count paragraphs of atrax) > 1) or ((count paragraphs of stra) > 0) then
if filecount > 1 then beep
activate
set da to text returned of (display dialog quotedinputfile & return & return & trstr & return & return & "1 1 means 1st audio track, 1st subtitle track\n1 0 means 1st audio track, no subtitles" buttons {"Cancel", "OK"} default button "OK" default answer "1 " & sot & " ")
set atr to (word 1 of da as integer) - 1
set str to (word 2 of da as integer) - 1
end if
updpr("Extracting Audio...\n\nHold ⌘. to Stop.\n", 1)
do shell script ffm & " -y -i " & quotedinputfile & " -q:a 0 -map 0:a:" & atr & "\\? -f s16le -ar 44.1k -ac 2 " & tmpextractedpcm
updpr("Loudmaxing...\n\nHold ⌘. to Stop.\n", 2)
do shell script mrs & " -p loudmax --parameter 0," & lmthre & " --parameter 1," & outvol & " --parameter 3,1.0 -i " & tmpextractedpcm & " -o " & tmploudmaxedpcm & "; rm " & tmpextractedpcm -- 2> /dev/null
updpr("Saving Audio...\n\nHold ⌘. to Stop.\n", 3)
do shell script ffm & " -y -i " & quotedinputfile & " -f s16le -ar 44.1k -ac 2 -i " & tmploudmaxedpcm & " -c:v copy -map 0:v:0\\? -map 1:a:0 -map 0:s:" & str & "\\? " & quotfilname & filext & "; rm " & tmploudmaxedpcm
set ii to ii + 1
updpr("Loudmaxing Done!\n\nHold ⌘. to Stop.\n", 4)
end repeat
try
say "Loudmaxing. Done!" using "zarvox" volume 1.0
on error
beep 3
end try
on error x number n
set gu to 600
if n is -128 then
set gu to 3
try
say "Loudmaxing Stopped!" using "zarvox" volume 1.0 without waiting until completion
on error
beep
end try
else
try
say "Loudmaxing Error!" using "zarvox" volume 1.0 without waiting until completion
on error
beep
end try
end if
--activate
display dialog x buttons {"OK"} default button "OK" with icon stop giving up after gu
display dialog "Do you want to open the temporary items folder?" buttons {"OK", "NO!"} default button "NO!" cancel button "NO!"
tell application "Finder"
activate
open tempfolder
--set w1 to (a reference to window 1) -- to close it later
end tell
end try
end open
on run
set ptm to quoted form of POSIX path of (path to me)
if (not ex(ptm & "Contents/Resources/mrswatson64") and not ex("/opt/homebrew/bin/mrswatson64")) or (not ex("/opt/homebrew/bin/ffmpeg") and not ex(ptm & "Contents/Resources/ffmpeg")) or (not ex("/Library/Audio/Plug-Ins/VST/LoudMax.vst") and not ex(ptm & "Contents/Resources/LoudMax.vst")) then
tell application "Finder"
activate
open (((path to me) as text) & "Contents:Resources:") as alias
display dialog "Please download the needed files\nffmpeg\nLoudMax.vst\nmrswatson64\nand drag them into the Finder window that just opened!\n\nSee Readme file for links" buttons ("OK") default button "OK"
end tell
return
end if
-- Handle the case where the script is launched without any dropped files
open (choose file with prompt "Select audio or video files to Loudmax:" with multiple selections allowed)
end run
If you're using shell scripting so extensively you might as well get rid of AppleScript completely, could be faster.
Code: Select all
#!/bin/bash
device=$(networksetup -listallhardwareports | awk '$3=="Wi-Fi" {getline;print}' | awk '{print $2}')
power=$(networksetup -getairportpower $device | awk '{print $4}')
if [ "$power" == "On" ]; then
power="Off"
echo -ne '\007' # beep
say "wi-fi $power"
else
power="On"
fi
networksetup -setairportpower $device $power
osascript -e "display alert \"wi-fi $power\" giving up after 1" # could be replaced with terminal-notifier as well
You are right; but often I use AS just to quickly add dialogs, use drag and drop etc.