Great Java - Caffeinated Babblings!

  • Home
  • Coffee Brewing HOW-TO
  • General
  • Web
  • Coffee
  • Java
  • Social Media
  • Coding
Caffeinated Babblings!

code

Copying Files into Xcode 27 Device Hub Simulator

October 2, 2026 by Mark Leave a Comment

I’ve been doing some iOS development with new Device Hub simulator in Xcode 27 and ran into what seems like it should be a really simple problem – copying the file from my Mac to the simulator.

With the older Simulator app I could just drag something like a JSON or CSV file from Finder onto simulator. It would show up in the Files app and I could select it using my app’s file picker.

That doesn’t seem to work with the simulator running inside the new Device Hub. Found a few hints on Google search, and eventually got a working combination to do it with simctl and rsync.

Copying It Somewhere Doesn’t Seem to Be Enough

Since the simulator’s filesystem is sitting right there on the Mac under:

~/Library/Developer/CoreSimulator/Devices/

My first thought was basically well I’ll find the right simulated Downloads directory and copy the file there. I think maybe did that long ago before figured out the drag and drop option.

I could copy my JSON file there, run ls, and see the file was there. Unfortunately the Files app couldn’t see it and neither did file picker in my application. No, restarting the simulated phone didn’t seem to make help.

Finding the Storage Used by Files

What finally worked for me was using the shared container associated with the Files app. This was a detail I found in a forum post.

First find the simulator you’re currently running:

xcrun simctl list | grep Booted

That gives you something similar to:

iPhone 17 Pro (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX) (Booted)

Take that device ID and ask simctl for the Files application’s group containers:

xcrun simctl get_app_container <DEVICE-ID> com.apple.DocumentsApp groups

You’ll get several entries back. The interesting one for this purpose is:

group.com.apple.FileProvider.LocalStorage

The path next to that appears to be the local storage used for files app “on my iPhone”.

Inside that directory is another directory named:

File Provider Storage

Copying my file there (with rsync) finally made it show up in the Files app.

The Slightly Weird Part

I originally tried copying the file using cp. That didn’t work correctly for me. In some of my testing I ended up with a zero-byte or unusable file. Maybe user error, I’m not sure.

Using rsync instead worked:

rsync -av my-file.json "<LocalStorage path>/File Provider Storage/my-file.json"

After doing that I could open Files on the simulator, select “on my iPhone”, and there was my file. No idea why and didn’t even Google it to see.

Making It Less Annoying

Great quick and easy use of Claude Code agent, create a script! Here’s a small script that finds the Files app’s LocalStorage container on the currently booted simulator and copies whatever file you give it. I didn’t test it with multiple simulators running.

#!/bin/bash

if [ "$#" -eq 0 ]; then
    echo "Usage: simfile <file> [file...]"
    exit 1
fi

LOCAL_STORAGE=$(
    xcrun simctl get_app_container booted com.apple.DocumentsApp groups |
    sed -n 's/^group\.com\.apple\.FileProvider\.LocalStorage[[:space:]]*//p' |
    head -1
)

if [ -z "$LOCAL_STORAGE" ]; then
    echo "Could not find the simulator LocalStorage container."
    echo "Make sure a simulator is booted."
    exit 1
fi

DEST="$LOCAL_STORAGE/File Provider Storage"

echo "Copying to:"
echo "$DEST"
echo

rsync -av -- "$@" "$DEST/"

Save it as simfile, make it executable:

chmod +x simfile

and then:

./simfile ~/Downloads/test-data.json

After executing it file should then be sitting under “On my iPhone” in the simulator’s Files app. Restart the simulator if you don’t see the update.

Good Enough for Now

There may be a cleaner (or official and proper way) to do arbitrary file transfers with Device Hub that I’ve missed!

Posted in: General Tagged: apple, code

Who Stuck the Pinball on my Backbox?

April 10, 2022 by Mark
Playfield on Backglass and DMD

For many creating a virtual pinball machine is one part woodworking, two parts electronics and wiring, and three parts installing/configuring/ troubleshooting software from several different contributors. One of the core components you’ll want in your setup is the Visual Pinball application. I’ve had great luck with the software, except for one issue with it knowing which monitor to use for which “part” of the “virtual” pinball machine. A common question I saw posted online is: “Why is my Visual Pinball playfield on the backglass or DMD monitor?” or “Why is my backglass not on the monitor I specified?” I noticed it was common because I did a lot of searching for the solution. I’ve attempted to detail some of the options I tried below. If you’ve tried everything with no luck, make sure to read the “Fix the Backglass” and “My Display Fix Script” sections below, as I think they will do the trick!

Fix the Backglass – The Easy Part

Many people aren’t aware that the backglass position problem is pretty easy to fix now. The latest backglass software version lets you put in a pixel position. So, if you have a 4K playfield, simply put the value @3840 to line 5 of your screenres.txt and you’ll never have to deal with that again! Since you put your monitors in a specific order, the coordinate system is much better than using a “display id” that will probably change.

What’s in a Display Number?

Visual Pinball determines a display “number” that’s not the same as the number you see in the control panel settings. If the number it finds for your display changes, VP still uses that number even though the proper monitor to use is now a different number after reboot. The tricks are all about trying to get Visual Pinball to use proper display or getting the number to not change.

Clean up the Registry

One option to try is to delete all the registry keys for your displays. Many people, when building a pinball cabinet, “try out” a few monitors, or upgrade video cards, etc. along the way. This leaves a lot of garbage in the registry. Heck, I had almost 30 entries but only 3 displays (multiple video cards and monitor trials gave me the mess). You can clean it up by deleting all the keys below (backup first, make sure you know how to use regedit). If this is the cause of your trouble, it might fix it, but it didn’t for me.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Connectivity HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\ScaleFactors

Turn on your Monitors in Specific Order

Oh, who wants to do this? Nobody, but if it will make it “just work” you might be happy with this approach. The idea is to make sure all your displays are on BEFORE the PC is turned on. This makes a lot of sense if you’ve seen a fast PC boot it might be at the login process before all your monitors are ready for a signal. I’m pretty sure every time a boot up the login screen starts on a different monitor before settling on my primary display. Some people swear by this method, but it didn’t work for me. I didn’t really want it to work, I’m using a smart power strip and just want one magic on button!

Use NailBuster utility to set Display at startup

Another trick is a utility that looks at what display is currently setup at coordinates 1,1 and set the registry entry used by Virtual Pinball to match. This was the first solution that seemed to work, but not 100% of the time. You can give it a try and see if works 100% for you.

https://www.nailbuster.com/wikipinup/doku.php?id=vp_display_issues&s#pupwinidfixexe

Use the “primary” flag at the startup of Visual Pinball (try this!)

I initially saw a flag browsing the repo for monitor setup and then, after trying it as “/primary”, found a post on Facebook from Nailbuster on the feature being part of 10.7 and to use “-Primary”. I changed the registry for vpx to use the “wrong” monitor and it worked. Even with vpx settings pointing to my DMD, it uses my main primary monitor properly! However, there are some caveats: this requires 10.7 and only works for Visual Pinball. Further testing with reboots showed sometimes even with vpx working with “right” monitor using this flag at startup actually forced my playfield to the wrong display. I think it’s worth a try to see if it helps (especially given the person who created it).

What works 100% of the time for me?

We could title this section “Your mileage may vary”. I took a brief look at the github repo (emphasis on brief – my observations are just a guess). It seems to be using Win32 calls to GetMonitorInfo and MonitorFromWindow to create a list, and using the display number according to the order of that list. It doesn’t check that information (and update it) at runtime, so if the ordering of items changes, it uses the same display number despite the change. When this happens, if you look at video preferences in VPX, you’ll see it puts an asterisk in the UI next to the “right” one.

Since my problem occurred every dozen or so starts, I tried a few scripts to list the displays to see if I could find one that always matched the ordering (and numbers) that matched the order Virtual Pinball used. What I found was that if you used the output from the Direct X Diagnostic tool, it always gave me the same order.

My Display Fix Script

I created a batch script that uses command line options to output the Direct X diagnostic tool, find the display listings, pick a display based on a unique resolution or display frequency, and update the registry entry Visual Pinball uses to match. Since most cabinet builds have a 4K display or a high refresh rate display, that can be used to identify which screen should be the “playfield”. This script could also be updated for use with Future Pinball (have some lines still testing in script). If all your displays are the same I’ve added support for that too, just read the readme in the zip file.

I created a zip file with a few scripts to pick from. I know a lot of builders aren’t PC experts, so I created some variations of the script with specific parameters so you can just drag and drop without setting command line parameters. You figured out that slot cutter on the router for that fancy t-molding. Let’s make this easy. Just copy the one you want (pick4kdisplay.bat for most) to your startup folder and reboot. You should see a command window pop-up after reboot pause for 5 seconds, then update the right settings. You don’t want to launch other things until this is done so if you have a delay in PinballY or Popper bump it up by several seconds (but you may not need this if takes you several seconds to pick a game!). Click here to download my zip of the batch scripts.

screenfixv3.zipDownload
Posted in: General Tagged: code, scripting, virtual-pinball

3D Print Automation with Dreamer-based Printers

January 3, 2021 by Mark

I recently created a network proxy for the FlashPrint software, which makes remote printing via Wi-Fi possible with the PowerSpec printer. While debugging that setup, I was able to observe the exact protocol and undocumented gcode commands used to send a file to the printer for printing. FlashForge doesn’t “stream” a print like many support with a tool like Octopi. Instead, a set of gcode commands are sent to the printer and then saved to the printer’s memory. Finally, then print begins. Since I can’t use Octopi with the FlashForge proprietary gcode, I needed something else.

Automation Option

The first goal was to enable automation for using another slicer. I created a set of Python functions to send a file to the printer. From there, I had what I needed to setup an Automater script on my Mac. This script monitors files in a directory and when one appears, it invokes the script with the filename. The trigger is files or folders added to /documents/start3dprint. The action is to run the shell script, passing my printer’s IP, port, and filename. This has worked well to start printing directly from Simplify3D

Print Monitoring

I also wanted an easy way to keep a window up in the corner of screen with print status. For this I created a simple Python GUI to connect to printer for monitoring and/or send a file. This can be used in conjunction with the automation to monitor print progress. I was able to compile it into a windows executable and Mac .dmg file. I was surprised how well the UI toolkit and compilation worked.

I hope after some more testing I’ll feel comfortable releasing it to others to try.

Posted in: automation, General Tagged: 3d-printing, automation, code, python, scripting

Copyright © 2026 Great Java - Caffeinated Babblings!.

Taste WordPress Theme by ThemeTaste

imunify-bot-check