Use AppleScript to change System Preferences > App Badges - macos

I'm trying to use AppleScript to control System Preferences in the background. Specifically, I am trying to Enable / Disable "Badge app icons" for each app. There is no global way to enable / disable badge app icons in system preferences. This must be done per app.
Any idea how this might be done?

Your question is broad, but here are some pointers:
While System Preferences.app can be controlled from an AppleScript, support is limited to revealing (opening) the application to a specific pane and anchor (tab).
Your best bet is to modify the underlying SQLite 3 database in which the per-application notification preferences are maintained - this answer will hopefully get you started.
macOS comes with the sqlite3 CLI.
From what I understand, while AppleScript has - limited - support for accessing SQLite databases via the Database Events app, using do shell script to call the sqlite3 utility may be the better option.
(In fact, in a brief test I wasn't even able to open a database in AppleScript on my macOS 10.12.4 machine)

Related

UI Automation for AppleTV system using XCode

Is UI automation available for the main menu of the Apple TV and not a specific application? I already setup the whole UI testing thing using XCode and tried using the remote control but it is only available for the application that was defined using XCUIApplication.
So is it possible to control the whole system rather than a specific application? I was thinking of something similar to pyatv but using XCode since I might be able to get more information concerning the current focused apps and so on.
There is an API XCUIApplication(bundleIdentifier: ) to interact with not-AUT apps. You need to substitute the right identifier for this Springboard-like interface. Maybe it is a Headboard, but I'm not sure.
Bundle identifiers of tvOS apps https://github.com/rzakhar/XCTApps/blob/master/Sources/XCTApps/tvOS.swift

Can we disable user interactions with other applications in mac while our app is running?

I am working on a mac based application and need guidance on one of the features, what I am trying to do here is
When my app launches I don't want the user to interact with any other application unless the user hits the close button of the app. No keyboard shortcuts should be enabled for mac like cmd+spacebar etc.
My question is if this is doable? Is there official documentation from apple which says it won't allow doing this due to some technical reason?
macOS has supported "kiosk mode" since 10.6; it allows your application to:
Hide / deactivate the dock, menu bar and Apple menu
Disable switching and hiding of your application
Prevent restarting or shutting down the computer
Broadly,NSApplication exposes a bitmask property, NSApplicationPresentationOptions, that lets you select the combination of settings you want to use.
The best resource to read further is the archived documentation that #KenThomases located here and here.

Launch Firefox from Finder with logging modules

I have found this site: https://developer.mozilla.org/en-US/docs/Mozilla/Debugging/HTTP_logging
My problem is: The settings for about:networking only work for the current session. And I have no interest to always start Firefox from the console. Is there a way to launch Firefox (under Mac OS X) via Finder and to permanently enable those logging features?
BG
I'm not a Mac user, so this might be not the best way. However, you might try using an approach similar to running Firefox with multiple profiles, as documented here on MDN. It suggests creating an Automator application that runs a shell script. You can follow this guide, which tells you to:
Open Automator
Go to File->New->Application
Choose Utilities group under Library
Drag Run Shell Script to the workflow pane on the right
Paste the script used to run Firefox with logging enabled
Choose Save As and store it somewhere
You should be good to go.

Modify defaults of sandboxed application from non-sandboxed app

I have an application which I'm now sandboxing. I do automated acceptance testing using the accessibility API from a different process. Before sandboxing, the test suite used CFPreferencesSetValue and friends to set certain default values for the application.
After sandboxing, the defaults are read from ~/Library/Containers/BUNDLEID/Data/Library/Preferences but the CFPreferencesSetValue functions only writes to ~/Library/Preferences as far as I understand.
Is there a way to programmatically write preferences to the sandboxed preferences without e.g. hardcoding the location and modifying the plist directly, or using the defaults command line utility.
One solution is to add an "Application Group" to your sandboxed app, thereby allowing other apps of this group to share its preferences, see: Reading NSUserDefaults from helper app in the sandbox
Actually, there is a better way, see the answer to my own question here: How does OS X's defaults command get access to prefs of sandboxed apps?
The trick is to use the full path to the preference file in the sandbox container, minus the ".plist" extension, as the application ID.

How to make an Invisible / Hidden Cocoa Application

I want to develop a application like http://orbicule.com/undercover/ or
http://hiddenapp.com/.
I know how I could do that for windows but I have totally no clue, what kind
of approach I would need for mac os x, cocoa/xcode.
Is there anything I should be aware of when building applicatons / background services
with no GUI for mac os x?
The service will post data to the webpage with the usual data like geo location & IP
information about the machine so it should be able to access the internet too.
Please lead me to the right path.
It's fairly straightforward.
Go to:
Information Property List Key Reference
http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Introduction/Introduction.html
in the Launch Services Keys, you will see one called "LSBackgroundOnly" simply define this in your Info.plist and set it to true.
<key>LSBackgroundOnly</key>
<true/>
From the documentation:
LSBackgroundOnly (Boolean - Mac OS X)
specifies whether this application
runs only in the background. If this
key exists and is set to “1”, Launch
Services runs the application in the
background only. You can use this key
to create faceless background
applications. You should also use this
key if your application uses
higher-level frameworks that connect
to the window server, but are not
intended to be visible to users.
Background applications must be
compiled as Mach-O executables. This
option is not available for CFM
applications.
Your application will be a background application.
Give System Startup Programming Topics a read. Create a command line tool project, not a Cocoa Application nor a Cocoa Document-Based application. To provide a GUI to interface with it you'll want to use a separate application (ideally one you don't have to install with the "hidden" app, since you seem not to want it to be easily discoverable).
With the exception of AppKit (UI) stuff, the rest of the basic Cocoa frameworks is still available to you via the command line. This means you'd write the main logic of your app (the non-GUI parts) the same as you would otherwise.

Resources