Unix/Linux Go Back    

OSX Sierra transparent shell audio sampler.

OS X (Apple)

Kindly Note - This is a Single User Post by Forum Member wisecracker Regarding:
OSX Sierra transparent shell audio sampler..
Please Follow The Primary Link Above to View the Full Discussion.

Old Unix and Linux 12-31-2016
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
Join Date: Jan 2013
Last Activity: 26 April 2017, 4:40 AM EDT
Location: Loughborough
Posts: 1,184
Thanks: 354
Thanked 317 Times in 247 Posts
Well as all of regulars on here now know the code in the OP is broken as of OSX Sierra 10.12.2. It works fine on 10.12.0 and 10.12.1 but the latest version of Sierra broke the code.
See here...
Root access in OSX 10.12.2.
...for more details.
This code is a workaround for the error generated in the above URL.
The important part is this...

> /"$mypath"/Untitled.m4a
chmod 666 /"$mypath"/Untitled.m4a

...inside the function. It can be outside the function but fails on AudioScope.sh if it is. I have absolutely no idea why! AudioScope.sh now captures again using QT.
Here is the revised code to counteract the error in the above URL.
It works for me and I hope for others too.
The Applescript section has been altered to allow for time delays in program startup and initial setup before taking a recording. There is a very small amount of error checking that defaults to roughly a 1 second capture.
This fudge has taken me ages to solve and has taught me a lot about Apple and their attitude towards security. I can't blame them but it is a RPITA having to do workarounds.

# Usage:- [./]AUDIO_CAPTURE.sh <number_of_seconds_from_1_upwards>
# This DEMO shell script uses a virgin OSX Sierra install only, nothing else is required.
# The conversion for this DEMO is mono, 8 bit, unsigned integer at 48000 sps but it is
# easy to convert to just about anything, 'man afconvert'...
# This creates a sample which is then saved to '/"$mypath"/Untitled.m4a' which is then converted
# to '/"$mypath"/Untitled.wav' file. Both formats are then played using 'afplay'.
# From the current directory, './AUDIO_CAPTURE.sh 5' gives about 5 seconds of recording.
# Use the internal built in microphone as a test.

# Time for the recording.
# Some very basic error checking.
if [ "$seconds" = "" ] || [ "$seconds" -le "1" ]

# 'mypath' should be in Applescript format, NOT POSIX format.
# E.G. 'Users:myhome:Desktop'. There is no need for leading and trailing colons - see below.
# This could be a command line second argument but is not given '$2' here.

> /"$mypath"/Untitled.m4a
chmod 666 /"$mypath"/Untitled.m4a
osascript << AppleSampler
tell application "QuickTime Player"
	set savePath to "Macintosh HD:" & "$mypath" & ":Untitled.m4a"
	set recording to new audio recording
	set visible of front window to false
	delay 3
	start recording
	delay "$1"
	stop recording
	export document "Untitled" in file savePath using settings preset "Audio Only"
	close (every document whose name contains "Untitled") saving no
	tell application "System Events" to click menu item "Hide Export Progress" of menu "Window" of menu bar 1 of process "QuickTime Player"
	-- quit
end tell
# 'wait' added for fullness only.

# Use the function to create a _background_ recording.
SAMPLE "$seconds"

# Example of conversion to a WAVE file.
afconvert -f 'WAVE' -c 1 -d UI8@48000 /"$mypath"/Untitled.m4a /"$mypath"/Untitled.wav
ls -l /"$mypath"/Untitled.*

# Playback both files.
afplay /"$mypath"/Untitled.m4a
sleep 1
afplay /"$mypath"/Untitled.wav
exit 0


Just comment out the 'quit' part in the Applescript section to remove the annoying opening and closing of QT on the dock...

Last edited by wisecracker; 12-31-2016 at 09:43 AM.. Reason: See above.
The Following User Says Thank You to wisecracker For This Useful Post:
Neo (01-01-2017)