MacOS screencapture only taking images of Desktop - macos

I created an applescript shortcut to take screenshot (larger usecase). But the resulting saved screenshot is only of the Desktop, even if other applications are in focus. Here is my applescript snippet
do shell script "screencapture -dxi /private/tmp/test.png"
I am also compiling with osacompile and launching the app through the Finder. I've also checked file directory and permissions (+ System Preferences) while everything checks out.
If I was to execute this command from the terminal then it would run as expected. My guess is that by running the app by double-clicking int the finder then a different user is used and results in inadequate permissions.

Related

How to prevent the "XYZ would like to access files in your Downloads folder" message when an app opens files inside its own bundle?

I have an installer app that gets distributed inside of a notarized disk image. The app is a simple program that performs a few checks on the system and then launches the macOS installer to install a pkg that is contained with the app's bundle.
However, even though this app is inside a mounted disk image, and even though the file it's trying to open is inside its own signed and notarized bundle, it still triggers the "App would like to access files in your Downloads folder" if the dmg is located in the user's Downloads folder, which it almost always will be.
Is there any way to get this app to launch the installer without triggering this message? The entire point of the app is to try and make the installation process as smooth and seamless as possible. The explicit goal is that opening it will go directly into the mac installer with no warning messages, interruptions, or any other sort of dialog box that risks confusing or alarming the user.
Note: just distributing the pkg on its own is not an option, because the purpose of this app is to work around a bug in macOS's installer on Apple Silicon macs. The pkg is Intel only, and if I add a script to it that executes when the pkg opens, then it will confusingly display a warning message to the user twice, once when Installer.app opens as an arm64 process, and then again when it relaunches as an x86_64 process.
This is an annoyingly roundabout workaround, but I managed to do it using launchd.
The gist of the method is to create a plist file in the user's temporary folder specifying a launchd job that starts on demand and just calls /usr/bin/open to open the pkg file inside the application bundle, and then call launchctl to load it. Once the installer is open, remove the launchd job.

Calling open in Terminal in MacOS brings another program to the foreground

I have two application bundles (called ProgramA and ProgramB) that I have written for MacOS. If I use open in Terminal to launch one of them it will launch just fine. But if I try to use open to launch the other one while the first one is open, it will instead bring to the foreground the already launched app. For instance, if ProgramA is already open and I use open -a ProgramB, Program A will instead come to the foreground.
I know I can use open -n -a ProgramB to ensure a new app is launched, but I would like to keep the behavior of bringing the app to the foreground if it already running. If I double-click the icon in Finder the apps will open as expected. The apps are being launched by another app so just using Finder isn't an option.
I thought maybe the issue was a duplicate key in the Info.plist that is used by the system, but that doesn't seem to be an issue. The values for the following keys are unique between the two apps:
CFBundleIdentifier
CFBundleExecutable
CFBundleName
Is there a way I can get open to launch the correct app if other app is already running?

How to start Mach-O file

I have created a small Cocoa application and built a Mach-O file using cross-platform tools. It is working Ok.
If I bring the Mach-O file to Mac (MacBook Pro OSX 10.11) it appears with Terminal icon in the Finder. If I double-click it, it opens unix Terminal window and starts the application from within the Terminal. Once my app starts, it opens its own window and works as expected. Of course, the Terminal window besides the application looks ugly. How do I make it start without opening the Terminal window?
My guess there should be some flag in Mach-O file to indicate it's a GUI application and doesn't need a Terminal, but I haven't found anything like that.

Where are OS X Terminal Window Groups saved

I know you can save Window Groups in Terminal using Windows > Save Windows as Group…, as explained in Mac OS X / Open terminal with specified windows.
However, where does Terminal save these states? I switch between an iMac and MacBook and want to sync these settings somehow. I'm thinking I could use a reverse symlink between the settings and Dropbox, but I need to know where they are first.
Window groups are saved in a plist file at ~/Library/Preferences/com.apple.Terminal.plist. You an edit these using the plist file editor that comes with XCode ('open .apple.Terminal.plist' from a shell is sufficient if you've got XCode installed).
Fortunately you don't have a catch-22 when editing this file from a Terminal window. Terminal doesn't automatically checkpoint the file on exit, so you can edit the file, exit Terminal, then restart your Mac in order to refresh the data from the file.

Replaced Finder kiosk

I am trying to make a kiosk, I actually wanted to lauch my app before the Finder got launched, I wrote the following command:
defaults write com.apple.loginwindow Finder ~/Desktop/myapp.app
and it worked, but now I have a huge issue, my Finder wont get launched at all, instead everytime my application is launched when I press the Finder, Before I was getting erroR -10810 but I fixed that. I tried reversing the process but it isnt working. My mac is useless and I cant get to my files.
Target is to reverse the process and make my finder works again as normal

Resources