Jump to content
You must now use your email address to sign in [click for more info] ×

Thinning multi architecture Affinity apps under MacOS via Python to reclaim disk space


v_kyr

Recommended Posts

The following thinapp.py Python 3 script can be used on macOS systems to thin the multi-architecture Affinity apps (the FAT binaries, containing "x86_64" and "arm64" architectures) to the one only specific architecture just required by the particular Mac platform ("x86_64" or "arm64")This will reclaim some disk space.

Important prerequisites in order to make use of the thinapp.py Python script:

  1. Python 3 is installed on your MacOS system
  2. MacOS lipo from the Xcode development CLI tools is installed and can be find under /usr/bin/lipo
    ...or... an alternative GO based lipo from https://github.com/konoui/lipo/
  3. A working file command is available and can be find under /usr/bin/file

In order to check for the needed prerequisites, you can perform a corresponding which command execution in Terminal.app:

  1. > which python3
    /Library/Frameworks/Python.framework/Versions/3.10/bin/python3
  2. > which lipo
    /usr/bin/lipo
  3. > which file
    /usr/bin/file

If all of the above prerequisites are met, you can execute the thinapp.py Python 3 script in Terminal.app like this to get a short help overview...

Quote

> python3 thinapp.py                                                                                                                                                                      
usage: thinapp.py [-h] -app APP_DIR [APP_DIR ...] [-o OUTPUT_DIR] [-arch ARCHITECTURE]

Quote

> python3 thinapp.py -h                                                                                                                       
usage: thinapp.py [-h] -app APP_DIR [APP_DIR ...] [-o OUTPUT_DIR] [-arch ARCHITECTURE]                                                                                                                                                                                          
options:                                                                                                                                       
  -h, --help            show this help message and exit                                                                                       
  -app APP_DIR [APP_DIR ...], --app_dir APP_DIR [APP_DIR ...]                                                                                 
                        The app to thin                                                                                                       
  -o OUTPUT_DIR, --output_dir OUTPUT_DIR                                                                                                       
                        Where the copy of the app is stored; defaults to working directory                                                     
  -arch ARCHITECTURE, --architecture ARCHITECTURE                                                                                             
                        The architecture to thin to; default: python's machine architecture

If you apply execution rights to the thinapp.py Python 3 script, via "chmod +x thinapp.py" in Terminal.app, then you can also execute the script via it's filename directly just by calling it, aka thinapp.py or thinapp.py -h .

For the -arch option argument supported architectures are x86_64 or arm64, in order to thin an app to an just Intel or Arm platform specific app only here!

Now in order to thin let's say Affinity Designer.app to contain just the Intel "x86_64" architecture and thus to strip out the "arm64" architecture from it's FAT binary app, you would call thinapp.py this way ...

Quote

> python3 thinapp.py -app /Applications/Affinity\ Designer.app -o /Users/<yourusername>/tmp -arch x86_64

... which in turn would then create a duplicate copy of "Affinity Designer.app" under the by the -o option as argument given file path "/Users/<yourusername>/tmp" and then process to thin it there under the "/Users/<yourusername>/tmp/Affinity Designer.app" file path. The as -arch option given x86_64 argument tells thinapp.py to keep just that x86_64 architecture, meaning that the arm64 architecture will be stripped out of the FAT binary app.

After the script has finished it's work, you can compare the ADe sizes under "/Applications/Affinity Designer.app" and "/Users/<yourusername>/tmp/Affinity Designer.app" in order to see how much space has been reclaimed due to the architecture thinning process. Next you can start the thinned app from "/Users/<yourusername>/tmp/Affinity Designer.app" in order to see if it operates well. - If all is fine, you can remove the initial "/Applications/Affinity Designer.app" and replace it with the thinned one from "/Users/<yourusername>/tmp/Affinity Designer.app" (... so exchanging the initial with the thinned app).

What you can expect from thinning the V1 apps of ADe, APh and APub size wise is ...

  • ADe v1   = initially ~2.59 GB after thinning to x86_64 it has then ~1.69 GB
  • APh v1   = initially ~2.65 GB after thinning to x86_64 it has then  ~1.71 GB
  • APub v1 = initially ~2.60 GB after thinning to x86_64 it has then ~1.65 GB

Here's the thinapp.py Python 3 script:

And as always, have fun!

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

Here's an additional hint for those who want to try out the thinapp.py Python 3 script, but don't want to install therefor the huge Xcode dev kit just in order to get a MacOS lipo command installed under /usr/bin/lipo for your MacOS system. - NOTE however that these alternative lipo binary versions (which are written in the GO programming language) do probably need and only run on MacOS versions >= 10.12 (Sierra) then.

The alternative lipo version can be found here ...

... the corresponding already build lipo binaries for it can be always found under it's latest release version there ...

... after downloading the respective binary file (the one you need for Intel or Arm MacOS platforms), you have to rename it then to "lipo", apply execution rights for it and afterwards copy it into the /usr/bin directory. In order to have a /usr/bin/lipo binary then on your system.

So for example here the steps to perform for an MacOS Intel platform then in/via Terminal.app would be ...

  1. > mv lipo_macOS_amd64 lipo      // renaming the file
  2. > chmod +x lipo                             // adding execution rights to the file
  3. > cp lipo /usr/bin                           // copying the file into /usr/bin

Now you should have hopefully a running lipo version then on your MacOS system under /usr/bin/lipo!

 

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

  • 1 month later...

For those more used to GUI apps here's a Python TKinter based GUI version of the thin architecture script program.

gui1.jpg.1da79c3f25db0cd11966102fa89e2e40.jpg

  1. Select a multi-architecture (universal) app to process on and thin, use the (...) button to select.
     
  2. The output directory where to place a copy of the app into and on which to operate processing, use the (...) button to select.
    - As default the directory the Python script is started from is used, but you should change that to some more suitable output directory.
     
  3. The architecture to keep and thin for, the unselected arch will be stripped out. So for the above in the screenshot shown selection,
    x86_64 will be kept and arm64 will be stripped out (removed). - As default the OS architecture will be determinded and preset to be kept.
     
  4. The THIN APPLICATION button starts the whole thinning processing, during processing it will be disabled in order to not be pressed again.
    After processing has been completed (when "...Done!" is shown in the console view bottom) it will be auto enabled again.
     
  5. A console output view, which shows processing states and thus gives informations about what is actually done.
     
  6. A Clear Console button which clears the console contents on demand. During processing it will be disabled in order to not be pressed and
    thus all processing informations are shown. After processing has been completed, it will be auto enabled again.
     
  7. A Reset All button which resets settings to their defaults. During processing it will be disabled in order to not be pressed during processing.
    After processing has been completed, it will be auto enabled again.
     
  8. The EXIT button which quits the app. - During processing it is kept enabled in order to offer a sort of emergency exit on user demand, by
    deleting running threads and subprocesses and quitting the python script.


gui2.jpg.d25250b5d7f6914657761ed4dba448bd.jpg

gui3.jpg.bd9a0c5fc7ac5b7a407251005474cda5.jpg

 

When the script has finished it's processing (when "...Done!" is shown at the bottom of the console output), you can compare the size of the initial univeral App with the new copied and thinned one, in order to see how much space has been reclaimed due to the architecture thinning process. Next you can start the thinned app from the place you stored that (the output directory) in order to see if it operates well. - If all is fine, you can remove the initial App and replace it with the thinned one from the output directory (... so exchanging the initial with the thinned app).

NOTE: Since this ThinApp GUI version does pretty much the same as it's above CLI counterpart version, the same preconditions apply here (see above in this thread for the needed preconditions). Namely you will need to have a runnable LIPO command installed on your MacOS system, in order to make any use out of this script!

This python gui app script can be started from inside a terminal by performing simply this common python3 calling way ...

Quote

> python3 thinappgui.py

... instead you can also apply access rights inside terminal for it, in order to make it executable and then start it via a double click in Finder etc.

Quote

> chmod +x thinappgui.py
... afterwards you can perform a double click on the script to start it ...

Here's the thinappgui.py script as a download:


IMPORTANT UPDATE NOTE:  

Forgotten to reactivate the skipping of scanned ICC files, which are now again skipped. This would mostly only affect Affinity apps and not other third party apps!

You may wonder why have those ICC files to be explicitely skipped? - Well the MacOS Affinity v1 distribution apps (...probably the v2 apps too?), have all their included ICC files strangely/falsely setup with execution rights (so all ICC files are marked as being executable inside Affinity apps). And since the script intern used MacOS file command gives back all mach-o exetuables, it here also thinks that those ICC files are then exectuables, which in turn afterwards irritates the as a subprocess called LIPO command, which then tries to thin those ICC files too! - Of course LIPO can't strip/thin ICC files, as those aren't mach-o executable files and thus it will choke about those. So ICC files when falsely setup to be executable have an impact on the whole processing and thus must be skipped here! - BTW, some PNG files are also falsely marked as executables inside the distributions, but don't have an impact here, since the MacOS file command recognizes those PNGs as to be images and not mach-o executables, which in contrast it doesn't recognize for executable ICC files!

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

Both the CLI thinapp.py and the GUI thinappgui.py versions have been updated, in order of skipping as default falsely setup executable ICC files, as can be found inside the Affinity MacOS distributions! - See above for an explanation why those executable ICC files inside Affinity apps would have an impact under MacOS here!

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

  • 9 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.