Skip to main content

We've had issues with the computers here after a migration with some important fonts being disabled. I made this script up to quickly fix the issue, I'm no scripting expert, I just wanted a quick way to do this for 200+ computers. I want it to run the script when the user logs into the computers. I get 2 different errors. I understand both but don't know how to fix them.



First error ----



/Library/Application Support/JAMF/tmp/fontfix.applescript:65:80: execution error: An error of type -10810 has occurred. (-10810)



Second error ----



Script result: 2016-09-27 11:02:52.314 osascript[2788:334116] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2016-09-27 11:02:52.315 osascript[2788:334116] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2016-09-27 11:02:52.315 osascript[2788:334116] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2016-09-27 11:02:52.315 osascript[2788:334116] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2016-09-27 11:02:52.394 osascript[2788:334116] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2016-09-27 11:02:52.395 osascript[2788:334116] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data



The script I'm using is below. I'm guessing these errors have to deal with it trying to open an app not being the current user that is logged in. What can I do to fix this issue? If I run the policy from terminal on the computers it works, but when it is run by its trigger it fails with those errors.



tell application "Font Book" to set {fontNames, fontEnableds} to {name, enabled} of font families

set activeFontsList to {}
set inactiveFontsList to {}
repeat with i from 1 to (count fontEnableds)
if (item i of fontEnableds) then
else
set end of inactiveFontsList to item i of fontNames
end if
end repeat

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set inactiveFontsList to inactiveFontsList as text
set AppleScript's text item delimiters to astid

set desktopPath to ("Macintosh HD:Users:Shared:" as text)
writeFile of inactiveFontsList to (desktopPath & "InactiveFonts.txt")

on writeFile of txt to destPath
set accessRef to (open for access file destPath with write permission)
try
set eof accessRef to 0
write txt to accessRef
end try
close access accessRef
end writeFile

set lf to (ASCII character 10)

tell application "Font Book"

set savedListSpec to (desktopPath & "InactiveFonts.txt")
set savedList to open for access savedListSpec
repeat
try
set typefaceToReactivate to (read savedList before lf)
on error
exit repeat
end try

if (offset of "*" in typefaceToReactivate) is 0 then
try
set enabled of typeface typefaceToReactivate to true
end try
end if

end repeat

end tell

tell application "Font Book"
quit
end tell

Hi,



This is because AppleScript is run as root from the logged in User Interface



We can use



"sudo -u $(ls -l /dev/console | awk '{print $3}')" /path/to/applescript



Refer the below links



https://jamfnation.jamfsoftware.com/discussion.html?id=17457
https://jamfnation.jamfsoftware.com/discussion.html?id=17245



Thanks & Regards,
Karthikeyan


The fonts being disabled was causing a piece of software we needed to install on all computers to fail. I've only been using jamf for about a week so I had no idea I could do this, but I just attached the script to the policy for the software we were trying to install and set it as a pre-install script. So all users just goto self-service and when the go to install that software it runs the script first and that solved all the issues I was having.


@karthikeyan.mac , I'm getting the same errors but with cocoaDialog. I want to use your workaround, but I can't seem to get it to work. I put the command into a variable and am trying to run it with another variable that has the path to the cocoaDialog binary. (I'm borrowing pieces of a script by @mm2270.)



So, this is what the variables look like:



cdPath="/Library/Application Support/JAMF/bin/cocoaDialog.app/Contents/MacOS/cocoaDialog"
runAsUser="sudo -u $(ls -l /dev/console | awk '{print $3}')"


I was triggering the dialog box using this command:



promptUser=$( "$cdPath" msgbox 
--title "$companyName"
--button1 "Continue"
--icon-file "$companyLogo" )


When the JSS runs the script, it throws the errors mentioned in the OP. Curiously, the functions of the cocoaDialog box works fine.



Now I'm trying to use the sudo workaround, but when I put promptUser=$( "$runAsUser $cdPath" msgbox it keeps telling me:



sudo -u username /Library/Application Support/JAMF/bin/cocoaDialog.app/Contents/MacOS/cocoaDialog: No such file or directory.



I tried to quote the path:
promptUser=$( "$runAsUser '$cdPath'" msgbox
promptUser=$( "$runAsUser "$cdPath"" msgbox



And they all give me the "No such file or directory" error (with single or double quotes around the path to cocoaDialog, even).



I try some other oddball combinations:
promptUser=$( "$runAsUser" "$cdPath" msgbox
promptUser=$( "$(runAsUser) $cdPath" msgbox
And so on, but just can't seem to get it to work.



I even tried creating a new variable sudoCD="$runAsUser $cdPath" and calling that, but it gives me similar messages.



If you couldn't tell, I'm still a novice at scripting. I'm sure I'm just missing something simple... Any ideas? Oh, I did just put your command into the cdPath variable as one long command, and it still didn't work.



Update: If I add eval in, like promptUser=$( eval "$runAsUser $cdPath" msgbox , then it doesn't give the "No such file or directory" error when I run the script locally, but when the JSS runs it remotely, then I get syntax error near unexpected token `('.


Reply