Prevent Mac from shutting down while running script - command-line

I have sometimes been running scripts overnight, only to come back in the morning to find that the mac had shutdown/restart because of an update or other reason. I was wondering if there is a way to prevent this from happening while a script is running in the terminal?
THanks

If you are using El Capitan (other osx might work too):
You can turn off install updates settings in "System Preferences" to prevent auto updates. Go to System Preferences => App Store => click the lock at the lower left of window to make changes => uncheck the "Automatically check for updates" and the boxes below.
enter image description here
Go to System Preferences => Energy Saver and click "Schedule" at lower right of window. Check to see if you have set a auto-shutdown time for your Mac. If so, disable it to prevent Mac from shutting down by itself. If it's not the case, don't change any settings.
Hope this helps! P.S. my first Stack Overflow answer!

Related

Mac OS: Remember Security & Privacy options for app while developing

I am developing a Mac OS app that accesses information like capturing the computer screen or controlling the mouse. (The app is just for personal use)
This works fine in the beginning. When my app tries to access a feature, I get asked to allow this in the system preferences (See dialog below) and if I do so, I can access the content. And as long as I don't change anything in my code I can rerun the app as often as I want and the permissions stay intact.
My issue is that every time I change something in the code, I also need to grant the permissions again to the app. Can someone please help me and explain why and what I can do to prevent this?
Mac OS: Catalina 10.15.7
Thanks so much for the help!
So even if it seems that you actually have to uncheck and check the box in the privacy settings over and over again, this doesn't mean you have to do it yourself all the time.
What helped me is recording an Automator workflow that checks the boxes for me. You can then run this workflow in a build phase to run it on every build.
Steps:
Open the window for the Security & Privacy settings
Open automator
Create a new workflow
Click the red record button at the top right (You might need to whitelist Automator in the Security & Privacy settings as well)
Record the steps that you normally do to enable the Privacy for your app (uncheck/check the respective box)
End the recording in automator and run the workflow once to ensure it works
Set the Automator workflow playback speed to the max (10x) to speed things up, also set the timeout to 0
Save the automator workflow to the disk
In Xcode click on your Target and switch to the 'Build Phases' tab
Click the '+' > 'New Run Script Phase'
Add the following shell script (Replace the path with the path to your Automator workflow file)
/usr/bin/automator ~/MyFolder/MyWorkflow.workflow
You might need to whitelist Automator in the Security & Privacy settings under 'Accessibility' as well
You will need to leave the Security & Privacy settings window open if you didn't include a step in your workflow to actually open it beforehand.
Now when you build/run the app the Automator script should do the work for you and the Privacy settings should be setup correctly.

Mac app disappears when window is closed then another app is selected

I created a new macOS project in Xcode 11.4 where the language is Swift and user interface is SwiftUI. Without making any changes to the code in the project, the app will disappear from the dock by performing the following steps:
launch the Mac app by running the Xcode project
close the main window of the Mac app
select another running app such as Safari
the original Mac app disappears from the dock with no way to access it
This behavior does not happen if the window of the Mac app is open. I can select other running apps then go back to the original Mac app with no problems.
This behavior is known as Automatic Termination. I find it a misfeature, but Apple considers it a feature.
Your app may not have actually quit. It may just appear to have quit. "Launching" it again will just make it reappear in the Dock. It's also possible that some apps which look like they're still running have actually been terminated by the system. In theory, if you try to switch to them, they will be launched and told to restore their previous state to maintain the illusion that they were running all along. In practice, apps (even Apple's) rarely properly restore things to exactly how they were.
The process list in Activity Monitor is a true reflection for what is and is not actually running. Look there to determine if your app has really been terminated.
A developer is supposed to have to opt-in to Automatic Termination because it requires explicit coding of state restoration. However, Xcode's app project/target templates have it enabled by default. You can remove the NSSupportsAutomaticTermination key from your Info.plist to disable it.
Likewise, you'll presumably want to disable Sudden Termination, too, if you're not prepared to support it. You would remove the NSSupportsSuddenTermination key.

iPhone not appearing in Develop menu in Safari

On my "Develop" menu, in Safari, the iPhone no longer appears after updating Safari to the latest version, making it impossible to inspect and debug sites and apps.
I restarted the iPhone, killed and relaunched Safari, restarted my Mac too, but the issue is still there. Affects both Safari mobile and phonegap applications.
Anyone experienced the same problem?
FWIW, I tried all of these suggestions, and it worked briefly after resetting Privacy & Location settings but stopped working immediately after.
What ended up working as a long term solution was to turn both WiFi and Bluetooth off on the iPhone while connected to the Mac.
Turns out, my issue was that the update to the latest iOS version disabled the "Web Inspector" settings on my iPhone.
To re-enable it, go to Settings > Safari > Advanced.
In our case we needed to reset the trust between iPhone & Mac. From iPhone Settings > General > Reset choose reset Privacy & Location and also Network Settings. The phone reboots, we reconnected to the laptop, tapped Yes to Trust this Computer and now Mac Safari can once again debug mobile Safari.
What helped for me was the following:
Open Xcode
On the Menu: Window -> Devices and Simulators
Check the Connect via network checkbox. (If it is already selected then uncheck it and re-check)
In my case, resetting only Privacy & Location did the job (but only temporarily, see update below!).
Try only resetting that before resetting your whole network settings for nothing!
Almost immediately after reset, the "Trust this Computer" popup appeared and after trusting my device appeared in the Develop menu.
Update:
I kept having regular issues with this (having to reset it multiple times per day, restarting Safari and a combination of other things) until I found the real fix here:
https://stackoverflow.com/a/58654871/167983
#BearSnowstorm:
One more tip to try - after trying many of the above suggestions I
turned off "Sync with this iPhone over Wi-Fi" in iTunes.
Voila! Got my iPhone into the Develop menu!
(for context, this is in Mojave 10.14.6, iOS 13.1.3, Safari 13.0.3)
My comment on that answer describes the same thing but updated for Catalina:
I had recurring issues with this and the only way I could make it work (sometimes) was to reset Location & Privacy, close Safari, unplug my device, etc. It was always a temporary fix though and the issues would come back very quickly. This however seems to work more permanently! I confirm what #Florian said: the setting was off by default for me, turning it on then off (after letting the sync finish) worked. On Catalina, this setting is named "Show this iPhone when on Wi-Fi" under General when you select your iDevice in the Finder.
Reading that answer my instinct was that it could not possibly make a difference, but it does! I have had zero issues since I did this. Try it!
Some cables (even official Apple Lightning Connector) don't support this feature because of some damage inside. My Lightning Connector was able to charge the iPhone but prevented to use dev tools on the Mac. I used another cable to successfully connect to dev tools.
In my case, this was totally a network issue.
Everything works well when I used 4G network.
If I use my wi-fi, safari failed to detect my device.
Turning off wifi on the iPhone allows it to appear in the develop menu.
The best and permanent solution in Catalina is to open a new Finder window, select in sidebar, then check 'Show this iPhone when on wifi'.
To disable caches (and to avoid constantly having to delete website data) open your site in a new Private Window. Changes to stylesheets will then update as normal.
Seems the front ports of my Mac Pro were not working correctly, plugged the cable on the keyboard port and I was able to connect to the dev tools.
I know all these tricks but after installing Catalina none of them worked. What DID work for me was Settings > Developer > Clear Trusted Computers. Strangely, the phone appears in the Safari Developer menu on the Mac, but the phone never asked to re-trust the computer!
The phone disappears again sometimes, but the same trick gets it back.
MacOS and iOS still look beautiful, but both are turning into a messy pigsty underneath. I sometimes wonder if Apple still even cares. :(
I've tried with the reset of Privacy and Location but it didn't work. What worked for me was disabling the hotspot from the phone. With the hotspot active Safari doesn't shows the iPhone in the developer menu.
Crazy but true, when i disconnected bluetooth and tried to check under develop option, connected device was shown.
In my case the only solution was to reboot my Macbook... stupid but effective solution
My solution was simply to move the cable to a different USB port.
reboot fix everything,works for me.
In my case, I was working from home and had a VPN tunnel to my work that was redirecting all traffic through my company's network. Disabling that revealed the phone in the Develop menu again.
As an alternative, connecting with VPN and disabling WIFI and Bluetooth works.

Why does NetBeans keep starting a new emulator?

More often than not, when I hit "Run" NetBeans keeps starting a new emulator yet never runs the application. Yes, I do wait several minutes because I know it can take awhile. This can happen if I start the emulator through the "Tools | Android SDK and AVD Manager" menu bar item. Eventually, things will start working properly (of course I have no idea what I did if anything to make it work). Sometimes I get the dialog that asks to select a running AVD or device or to start the AVD but often I don't get that dialog.
Anybody know what's going on here?
Thanks a bunch,
Bill

Moved Application to New Computer Won't Run

I have an application that I recently moved to another computer, where it won't run. Previously the application had a different name and a different target. I updated the new information and it runs fine on the original computer, but I can't get it to run on the iOS Simulator on the new computer. The play button is completely greyed out. Anyone have any ideas?
UPDATE: 8/8/2011 13:44
I'm not sure if this helps, but when I go to the Product menu and select "Edit Schemes" it is listing the old application target (which it says is missing). However, I can't find a way to change that in that menu.
FOUND SOLUTION:
I found that by going into the Product menu and selecting "Manage Schemes" that a new window came up. In this window I clicked a button that says, "Autocreate schemes now" and a new scheme with the new app name appeared. Then I went into the Product menu and clicked "Edit Scheme" and another window came up. In this menu, the new scheme was available from the "Scheme" drop down. I selected it, and now all is well.
Thank you, everyone, for your help.
In most all cases, this is caused by the configured SDK version of the application not being present on the newer computer. To adjust this, go to the project settings and adjust the Base SDK to a version that is present on the new computer.