Posts

Post not yet marked as solved
3 Replies
367 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
412 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
385 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
359 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
353 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
.
Post not yet marked as solved
10 Replies
2.5k Views
There is no way to script the Finder from a sandboxed app is there?Finder has no access-groups vai sdef, so the only way i could get this to work is by using <key>com.apple.security.temporary-exception.apple-events</key> <string>com.apple.finder</string>in the entitlements. Of course, this caused a rejection from Apple. Apparently, if i can convince the user to install AppleScript file(s) into FileManager.SearchPathDirectory.applicationScriptsDirectory it may work. Seems to be an high hurdle. Any other possible ways?I understand, it's a valid security concern. I'm only using AppleScript to get the Desktop icon names and positions, the Desktop View Options text size and icon size and the bounds of the Desktop window. I use the return data to 'memorize' and 'restore' various icon arrangements on the Desktop. Is there any other way to achieve this in an macOS app that would not be rejected? I expect not, since it appears only the Finder knows such information.Thanks,
Posted
by parker9.
Last updated
.