Topics

Multiple versions of an app


Carl Hoefs
 

Xcode 11.3.1 / macOS 10.14.6

I've written a small macOS app that performs user-configurable statistics over the course of days. It works fine, but I need to be able to run 8 such identical apps simultaneously. Each app needs its own unique bundle identifier (for settings/defaults, window placement, etc).

How can I use Xcode to produce 8 simultaneously runnable versions of my app? Or would it be more expedient to simply twiddle the Info.plist of copies of the app?

-Carl


Alex Zavatone
 

Duplicate the target 7 times and change the bundle ID for each.

You can also make a build operation that builds more than one target.  

Or just issue this script.
xcodebuild -project projName -alltargets
Or this one.

xcodebuild -target appCopy1 -target appCopy2

Is there a reason why you can’t open one copy of the app with a -n parameter?  You can build a script that does this 8 times to launch 8 copies of 1 app.

You could have an app as an AppleScript app to issue a shell script to do it.

on run
do shell script "open -n /Applications/Utilities/Terminal.app;
open -n /Applications/Utilities/Terminal.app;
open -n /Applications/Utilities/Terminal.app;
open -n /Applications/Utilities/Terminal.app;"
end run


Cheers,
Alex Zavatone


On Dec 16, 2020, at 1:43 PM, Carl Hoefs <newslists@...> wrote:

Xcode 11.3.1 / macOS 10.14.6

I've written a small macOS app that performs user-configurable statistics over the course of days. It works fine, but I need to be able to run 8 such identical apps simultaneously. Each app needs its own unique bundle identifier (for settings/defaults, window placement, etc).

How can I use Xcode to produce 8 simultaneously runnable versions of my app? Or would it be more expedient to simply twiddle the Info.plist of copies of the app?

-Carl








Carl Hoefs
 

On Dec 16, 2020, at 12:16 PM, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

Duplicate the target 7 times and change the bundle ID for each.
How to do duplicate a target (and rename it)? The Duplicate menu item has been removed.

Is there a reason why you can’t open one copy of the app with a -n parameter?
Each app has its own settings and defaults, so I can't just run one 8 times. Each needs its own unique bundle identifier.

-Carl


Ben Kennedy
 

On 16 Dec 2020, at 11:43 am, Carl Hoefs <newslists@autonomy.caltech.edu> wrote:

How can I use Xcode to produce 8 simultaneously runnable versions of my app? Or would it be more expedient to simply twiddle the Info.plist of copies of the app?
How about defining a new build setting and injecting that into the bundle identifier, then passing its value on the command line?

in project settings:

BUNDLE_ID_SEQ="0"
PRODUCT_BUNDLE_IDENTIFIER="com.example.foo.$(BUNDLE_ID_SEQ)"

then:

$ xcodebuild BUNDLE_ID_SEQ=1
(etc.)

-ben


Jack Brindle
 

There are several ways to do this. I don’t think you want to build eight separate Mac apps - it would require eight Notarization passes, which, at 5 to 10 minutes per pass, will take an hour or more just for the build.

Instead, I would find a way to consolidate the functions into a single app, with separate UIs for each function. That way the app is built once, run once, removed once, etc., making it much easier on the user.

Now, if you really want eight individual apps, create a single parent-app that contains the individual apps, launching them as needed (NSTask will do the job quite well). You might even be able to use a single embedded app, passing in command line arguments to customize the operation of each one. As for the preferences, there is no requirement that the system handle the app’s preferences. You can certainly create your own settings facility that saves the data to a file (located in ~/Library/preferences). Again, the command-line argument can tell the app which settings file to use.

This sounds like a fun little project (key word is little), similar to several I have created over the years. Making multiple target applications can be and usually is a pain, but proper application design will take a situation of this sort and make it much more elegant.

Good luck!
Jack

On Dec 16, 2020, at 11:43 AM, Carl Hoefs <newslists@autonomy.caltech.edu> wrote:

Xcode 11.3.1 / macOS 10.14.6

I've written a small macOS app that performs user-configurable statistics over the course of days. It works fine, but I need to be able to run 8 such identical apps simultaneously. Each app needs its own unique bundle identifier (for settings/defaults, window placement, etc).

How can I use Xcode to produce 8 simultaneously runnable versions of my app? Or would it be more expedient to simply twiddle the Info.plist of copies of the app?

-Carl






Carl Hoefs
 

On Dec 16, 2020, at 1:00 PM, Ben Kennedy <ben-groups@zygoat.ca> wrote:

On 16 Dec 2020, at 11:43 am, Carl Hoefs <newslists@autonomy.caltech.edu> wrote:

How can I use Xcode to produce 8 simultaneously runnable versions of my app? Or would it be more expedient to simply twiddle the Info.plist of copies of the app?
How about defining a new build setting and injecting that into the bundle identifier, then passing its value on the command line?

in project settings:

BUNDLE_ID_SEQ="0"
PRODUCT_BUNDLE_IDENTIFIER="com.example.foo.$(BUNDLE_ID_SEQ)"

then:

$ xcodebuild BUNDLE_ID_SEQ=1
(etc.)
Yes! This is sheer genius! Works perfectly!

Thanks Ben!
-Carl


Alex Zavatone
 


OK.  So, here’s how to launch them through an AppleScript.

on run
do shell script "open /Applications/Carl-o-matic-1.app;
open /Applications/Carl-o-matic-2.app;
open /Applications/Carl-o-matic-3.app;
open /Applications/Carl-o-matic-4.app;
open /Applications/Carl-o-matic-5.app;
open /Applications/Carl-o-matic-6.app;
open /Applications/Carl-o-matic-7.app;
open /Applications/Carl-o-matic-8.app;"
end run


Since they all have a different bundle and name, you wouldn’t need the -n argument then.

If you really needed to, you could build the name from a loop and launch them all.  

Cheers,
Alex Zavatone


On Dec 16, 2020, at 2:41 PM, Carl Hoefs <newslists@...> wrote:

On Dec 16, 2020, at 12:16 PM, Alex Zavatone via groups.io <zav@...> wrote:

Duplicate the target 7 times and change the bundle ID for each.

How to do duplicate a target (and rename it)? The Duplicate menu item has been removed.

Is there a reason why you can’t open one copy of the app with a
parameter?

Each app has its own settings and defaults, so I can't just run one 8 times. Each needs its own unique bundle identifier.

-Carl








Alex Zavatone
 



On Dec 16, 2020, at 3:18 PM, Jack Brindle via groups.io <jackbrindle@...> wrote:

Now, if you really want eight individual apps, create a single parent-app that contains the individual apps, launching them as needed (NSTask will do the job quite well). 

An awesome thing to do if you want to use NSTask is to check if there are any other instances of the app running.  I use a shell script to check if the PID exists.  If there aren’t, then one app automatically launches all the rest through either NSTask or a shell script.

The same shell script that I used before or a look as mentioned can be used to build the name and launch the other apps.

open /Applications/Carl-o-matic-1.app;
open /Applications/Carl-o-matic-2.app;
open /Applications/Carl-o-matic-3.app;
open /Applications/Carl-o-matic-4.app;
open /Applications/Carl-o-matic-5.app;
open /Applications/Carl-o-matic-6.app;
open /Applications/Carl-o-matic-7.app;
open /Applications/Carl-o-matic-8.app;
 
There are lots of ways to do this, but IMHO, the apps will have known names, just do it the easy way and open them instead of writing too much code.

Ben’s idea for the build is nice and crafty.  You can have a custom build scheme to handle that pretty nicely.

Alex Zavatone


Carl Hoefs
 

On Dec 16, 2020, at 1:33 PM, Carl Hoefs <newslists@...> wrote:

in project settings:

BUNDLE_ID_SEQ="0"
PRODUCT_BUNDLE_IDENTIFIER="com.example.foo.$(BUNDLE_ID_SEQ)"

then:

$ xcodebuild BUNDLE_ID_SEQ=1
(etc.)


Could this way also be used to name the app itself? 

Something like: PRODUCT_EXECUTABLE_NAME="MyApp$(BUNDLE_ID_SEQ)"
to generate MyApp1.app, MyApp2.app, etc...

-Carl


Alex Zavatone
 

That’s in your Build Settings 

$(TARGET_NAME)



On Dec 16, 2020, at 3:56 PM, Carl Hoefs <newslists@...> wrote:

On Dec 16, 2020, at 1:33 PM, Carl Hoefs <newslists@...> wrote:

in project settings:

BUNDLE_ID_SEQ="0"
PRODUCT_BUNDLE_IDENTIFIER="com.example.foo.$(BUNDLE_ID_SEQ)"

then:

$ xcodebuild BUNDLE_ID_SEQ=1
(etc.)


Could this way also be used to name the app itself? 

Something like: PRODUCT_EXECUTABLE_NAME="MyApp$(BUNDLE_ID_SEQ)"
to generate MyApp1.app, MyApp2.app, etc...

-Carl



Ben Kennedy
 

On 16 Dec 2020, at 1:56 pm, Carl Hoefs <newslists@autonomy.caltech.edu> wrote:

Could this way also be used to name the app itself?

Something like: PRODUCT_EXECUTABLE_NAME="MyApp$(BUNDLE_ID_SEQ)"
to generate MyApp1.app, MyApp2.app, etc...
Good point; you should be able to achieve that by changing PRODUCT_NAME.

-ben


Carl Hoefs
 

Yes - $(TARGET_NAME) is the correct identifier! 

Setting this also changes the executable name under ../MacOS and CFBundleName and CFBundleExecutable in the Info.plist.

Thx!
-Carl


On Dec 16, 2020, at 1:58 PM, Alex Zavatone via groups.io <zav@...> wrote:

That’s in your Build Settings 

$(TARGET_NAME)

<PastedGraphic-2.png>

On Dec 16, 2020, at 3:56 PM, Carl Hoefs <newslists@...> wrote:

On Dec 16, 2020, at 1:33 PM, Carl Hoefs <newslists@...> wrote:

in project settings:

BUNDLE_ID_SEQ="0"
PRODUCT_BUNDLE_IDENTIFIER="com.example.foo.$(BUNDLE_ID_SEQ)"

then:

$ xcodebuild BUNDLE_ID_SEQ=1
(etc.)


Could this way also be used to name the app itself? 

Something like: PRODUCT_EXECUTABLE_NAME="MyApp$(BUNDLE_ID_SEQ)"
to generate MyApp1.app, MyApp2.app, etc...

-Carl




Sandor Szatmari
 

What about using NSUserDefaults -addSuiteNamed:


Could you add subdomains for each of the areas for which you need to main discrete defaults?

Then manage each ‘suite’ in it’s own thread/subprocess etc

Then you could have one app, partitioned into subdomains internally.  I’m seeing a tabbed interface?

Sandor

On Dec 16, 2020, at 14:43, Carl Hoefs <newslists@...> wrote:

Xcode 11.3.1 / macOS 10.14.6

I've written a small macOS app that performs user-configurable statistics over the course of days. It works fine, but I need to be able to run 8 such identical apps simultaneously. Each app needs its own unique bundle identifier (for settings/defaults, window placement, etc).

How can I use Xcode to produce 8 simultaneously runnable versions of my app? Or would it be more expedient to simply twiddle the Info.plist of copies of the app?

-Carl







Alex Zavatone
 

A better explanation is that the info.plist uses that build setting, that environment variable as the name of the executable.  

There’s a little relationship between $(TARGET_NAME), $(PRODUCT_NAME) and $(EXECUTABLE_NAME).  These are defined in your target’s build settings and used in various places, such as our friendly info.plist.

These are good resources to help you make sense of them. Expect a few to be missing.


Make sure to save this as a PDF for future reference.

Looking forward ti hearing about the end result of this product you’re creating.

Alex Zavatone

On Dec 16, 2020, at 6:15 PM, Carl Hoefs <newslists@...> wrote:

Yes - $(TARGET_NAME) is the correct identifier! 

Setting this also changes the executable name under ../MacOS and CFBundleName and CFBundleExecutable in the Info.plist.

Thx!
-Carl


On Dec 16, 2020, at 1:58 PM, Alex Zavatone via groups.io <zav@...> wrote:

That’s in your Build Settings 

$(TARGET_NAME)

<PastedGraphic-2.png>

On Dec 16, 2020, at 3:56 PM, Carl Hoefs <newslists@...> wrote:

On Dec 16, 2020, at 1:33 PM, Carl Hoefs <newslists@...> wrote:

in project settings:

BUNDLE_ID_SEQ="0"
PRODUCT_BUNDLE_IDENTIFIER="com.example.foo.$(BUNDLE_ID_SEQ)"

then:

$ xcodebuild BUNDLE_ID_SEQ=1
(etc.)


Could this way also be used to name the app itself? 

Something like: PRODUCT_EXECUTABLE_NAME="MyApp$(BUNDLE_ID_SEQ)"
to generate MyApp1.app, MyApp2.app, etc...

-Carl





James Walker
 

On Dec 16, 2020, at 12:41 PM, Carl Hoefs <newslists@autonomy.caltech.edu> wrote:

On Dec 16, 2020, at 12:16 PM, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

Duplicate the target 7 times and change the bundle ID for each.
How to do duplicate a target (and rename it)? The Duplicate menu item has been removed.
I still see Duplicate on the menu that pops up when I right-click a target.


Alex Zavatone
 

On Dec 17, 2020, at 7:03 PM, James Walker <list2@jwwalker.com> wrote:



On Dec 16, 2020, at 12:41 PM, Carl Hoefs <newslists@autonomy.caltech.edu> wrote:

On Dec 16, 2020, at 12:16 PM, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

Duplicate the target 7 times and change the bundle ID for each.
How to do duplicate a target (and rename it)? The Duplicate menu item has been removed.
I still see Duplicate on the menu that pops up when I right-click a target.

That’s what I’ve used..


Carl Hoefs
 

On Dec 17, 2020, at 5:03 PM, James Walker <list2@jwwalker.com> wrote:



On Dec 16, 2020, at 12:41 PM, Carl Hoefs <newslists@autonomy.caltech.edu> wrote:

On Dec 16, 2020, at 12:16 PM, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

Duplicate the target 7 times and change the bundle ID for each.
How to do duplicate a target (and rename it)? The Duplicate menu item has been removed.
I still see Duplicate on the menu that pops up when I right-click a target.
Am I clicking on the wrong thing?
The target is the uppermost item in the left column in Xcode?
Or is it under the "Targets" column in Edit Scheme -> Build?
Neither one gives me a Duplicate ...
I'm using Xcode 11.3.1

-Carl


Marco S Hyman
 

Am I clicking on the wrong thing? 




Carl Hoefs
 

On Dec 17, 2020, at 5:25 PM, Carl Hoefs <newslists@autonomy.caltech.edu> wrote:
Am I clicking on the wrong thing?
Ah! The answer is "Yes"! I never clicked on the little reveal icon.
Thanks for pointing it out, Marco!
-Carl


On Dec 17, 2020, at 5:25 PM, Carl Hoefs <newslists@autonomy.caltech.edu> wrote:

On Dec 17, 2020, at 5:03 PM, James Walker <list2@jwwalker.com> wrote:

On Dec 16, 2020, at 12:41 PM, Carl Hoefs <newslists@autonomy.caltech.edu> wrote:

On Dec 16, 2020, at 12:16 PM, Alex Zavatone via groups.io <zav=mac.com@groups.io> wrote:

Duplicate the target 7 times and change the bundle ID for each.
How to do duplicate a target (and rename it)? The Duplicate menu item has been removed.
I still see Duplicate on the menu that pops up when I right-click a target.
Am I clicking on the wrong thing?
The target is the uppermost item in the left column in Xcode?
Or is it under the "Targets" column in Edit Scheme -> Build?
Neither one gives me a Duplicate ...
I'm using Xcode 11.3.1

-Carl


Alex Zavatone
 

In part of this thread, we talked about using build environment variables for um, stuff and things. Here’s a short little write up I did last year to show how massively useful they can be.

Using build configuration environment variables
Here are some of the strings:
$(BUNDLE_DISPLAY_NAME) - $(CONFIGURATION).entitlements
$(PRODUCT_NAME) - $(CONFIGURATION).entitlements

This gives us
MyApp - Debug.entitlements
MyApp - Release.entitlements
MyApp - Test.entitlements

In building paths for files used for builds, you can also use them to automatically create paths to files based on product name, build configuration or both.
Below is how to create build setting file path that uses app name and build configuration name dependent entitlements files.

$(SRCROOT)/../$(PRODUCT_NAME)/$(PRODUCT_NAME)-$(CONFIGURATION).entitlements

The big deal here is that you duplicate your target name and/or add a new build configuration, new entitlement files following a naming convention are automatically looked for. All you need to to is create them and they are automatically used in your build.

Cheers!
Alex Zavatone