Posts

Post not yet marked as solved
0 Replies
171 Views
Wanted to add some basic scripting capabilities for an AppKit Swift application on macOS. I looked at adding AppleScript support (i.e. Cocoa Scripting) and it, frankly, hurts my head. I then discovered that Swift provides for CommandLine.argc and Commandline.arguments. So, from Terminal, I can do open -a myApp --args arg1 arg2 arg3 and sure enough, MyApp starts and CommandLine.arguments contain arg1, arg2, arg3 along w/ the first entry which is the fully resolved path of the executable. Great! However, if myApp is already running when I execute open -a myApp --args arg4 CommandLine.arguments are not updated and I get the same values as when I originally started the program (i.e. arg1, arg2, arg3 and not arg4). So I added func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { parseCommandLine(); return true} to AppDelegate and while parseCommandLine is called for my second open -a command, it still points to the old CommandLine.arguments. Even tried returning false, but no difference. Is there a way for CommandLine to be refreshed if myApp is already running? Or a different way to get the same effect?
Posted
by parker9.
Last updated
.
Post not yet marked as solved
3 Replies
579 Views
I have a sandboxed/hardened app that is distributed outside of the MacAppStore. I want to allow the app to auto-update itself. I currently have the ability in the app to figure out if there is a newer version which then informs the user and gives them an option to download the app (currently it downloads to ~/Downloads in the app container). The app comes as a simple zip file that only includes the app itself. Once downloaded, then NSWorkspace.shared.open(URLtoDownloadedUpdate) will expand the zip and place the app in ~/Downloads. What I want is it to replace the current version of the app w/ this newly downloaded version. Is this possible? First, how do I find out where the old app is stored? And then how do I replace it with the new version when the old app is still running? I realize many people use Sparkle to do this instead of rolling their own. I simply do not want to depend on a third party.
Posted
by parker9.
Last updated
.
Post marked as solved
3 Replies
512 Views
Prior to Ventura, my app that only has a Menu Item does not have a Storyboard but does have a custom main.swift as import Foundation import Cocoa let app = NSApplication.shared let delegate = AppDelegate() app.delegate = delegate _ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv) And then in Info.plist, I added Application is agent (UIElement) YES so the app isn't displayed in the dock. Occasionally, the app now crashes on start. Is there documentation for creating a Menu item only macOS app without Storyboard? It's typically crashing in _NSCGSDisplayConfigurationUpdateAndInvokeObservers or in _NSCGSDockMesageReceive. Thanks,
Posted
by parker9.
Last updated
.
Post not yet marked as solved
3 Replies
875 Views
Doing a guard let cgImage = CGWindowListCreateImage(.null, [.optionIncludingWindow], cgID, [.nominalResolution]) else { print ("problem!"); continue } where cgID is a CGWindowID for a Desktop background image almost always returns an CGImage of the Desktop (minus any icons on the Desktop, of course). However, under Monterey, there is a finite possibility of the returned image to be simply gray or some chopped up version of the actual Desktop. This usually happens when Spaces are changed and code is triggered to update the image from a NSWorkspace.shared.notificationCenter notification named: NSWorkspace.activeSpaceDidChangeNotification. Is there a way to detect when the image returned is not correct? The else in the guard is never triggered and the cgImage is the correct size, just the wrong content. In fact comparing a good cgImage to a bad cgImage, there doesn't appear to be any difference. Documentation for .optionIncludingWindow says You must combine this option with the optionOnScreenAboveWindow or optionOnScreenBelowWindow option to retrieve meaningful results. However, including either option (e.g. [.optionOnScreenBelowWindow, .optionIncludingWindow]) can still result in an incorrect image. As an aside, https://developer.apple.com/videos/play/wwdc2019/701/ at the 15:49 mark shows using only the optionIncludingWindow, so not sure which documentation is correct.
Posted
by parker9.
Last updated
.
Post not yet marked as solved
2 Replies
744 Views
trying to make a simple simulation of a Newton's Cradle in Scenekit.if i have two balls starting in equilibrium and then give one ball an impulse, the dynamics are correct. the first ball comes back, hits the second ball. stops and all the momentum goes to the second ball. repeat. great!now three balls are placed in the cradle. again, take one of the end balls, give it an impulse so it flies up. comes back and collides. the two other balls move and the original ball bounces back. that's not physics. the correct behavior is the first ball after colliding, stops and the ball on the other end moves up. the center ball should not move. ever. apparently collisions are handled serially.playing w/ the timestep of the simulation doesn't appear to help (which also suggests collisions are handled serially).physically (for identical balls), during a collisin, the velocities should simply be swapped between pairs (assuming elastic collision). so i turned off collisions and used SCNPhysicsContactDelegate to be called when any two balls contact w/ func physicsWorld(_ world: SCNPhysicsWorld, didBegin contact: SCNPhysicsContact) and then simply swapped the velocities between the two nodes or gave each an impulse that would do the same thing. Doesn't really work since, some balls overlap and appear to be stuck for a bit.i think what i need is a way to find *all* contacts in a timestep so i can handle simultaneous collisions correctly. alas, don't see how to do that.any brillant ideas?this also implies scenekit simulation of billards can't possibly work at least according to Newtonian physics. 😟
Posted
by parker9.
Last updated
.
Post not yet marked as solved
0 Replies
620 Views
I was trying to use attributedText (NSAttributedString?) on a SKLabelNode in order to in-line some graphics with text. It does not seem to work. Same code but using an UILabel is just fine. Is it true that SKLabelNode's attributedText does not support in-line graphics?
Posted
by parker9.
Last updated
.
Post marked as solved
1 Replies
636 Views
Wrote a simple SceneKit app for rolling dice. To start w/ i just assumed the dice had a side dimension of 1 (though i did set a density to acrylic and did calculate and assign the mass to physicsBody!.mass). Simulation runs fine. Looks fine (pretty cool, actually).Then decided to try to use a realistic size of dice (i.e. instead of 1 meter, said to use 0.02 meter). Now the dice are constantly jiggling around. If i try to roll the dice, they basically move so fast as they can escape the box (collision failure).so then i decreased scene.physicsWolrd.timeStep from the default 1/60. However, as i go smaller and smaller on this value, the dice jitter even more (though they don't escape the box when rolled). there appears to be 'stochastic' forces acting on the dice that do NOT scale with the mass of the dice.any clue?
Posted
by parker9.
Last updated
.
Post marked as solved
4 Replies
703 Views
If the user does not select a image for the Desktop, then (at least in High Sierra)NSWorkspace.shared.desktopImageURL(for: NSScreen.main!)returns something likefile:///System/Library/PreferencePanes/DesktopScreenEffectsPref.prefPane/Contents/Resources/DesktopPictures.prefPane/Contents/Resources/Transparent.tiffwhich makes sense- a transparent tiff.How do i determine the color the user selected for the Desktop?
Posted
by parker9.
Last updated
.