Browse Source

Fixed setting icon on MacOS

merge-requests/413/head
eidheim 3 years ago
parent
commit
1f2aef713d
  1. 26
      share/set_icon.sh
  2. 4
      share/set_icon_macos.py
  3. 2
      src/CMakeLists.txt

26
share/set_icon.sh

@ -0,0 +1,26 @@
#!/bin/sh
# Based on https://stackoverflow.com/a/8375093
# TODO: Rez, DeRez and SetFile are deprecated, but I have not yet found replacement tools
# Sets an icon on file or directory
# Usage setIcon.sh iconimage.jpg /path/to/[file|folder]
iconSource=$1
iconDestination=$2
icon=/tmp/`basename $iconSource`
rsrc=/tmp/juci.rsrc
# Create icon from the iconSource
cp $iconSource $icon
# Add icon to image file, meaning use itself as the icon
sips -i $icon > /dev/null
# Take that icon and put it into a rsrc file
DeRez -only icns $icon > $rsrc
# Apply the rsrc file to
SetFile -a C $iconDestination
# Append resource to the file you want to icon-ize.
Rez -append $rsrc -o $iconDestination
rm $rsrc $icon

4
share/set_icon_macos.py

@ -1,4 +0,0 @@
import Cocoa
import sys
Cocoa.NSWorkspace.sharedWorkspace().setIcon_forFile_options_(Cocoa.NSImage.alloc().initWithContentsOfFile_(sys.argv[1].decode('utf-8')), sys.argv[2].decode('utf-8'), 0) or sys.exit("Unable to set file icon")

2
src/CMakeLists.txt

@ -73,7 +73,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES Linux|.*BSD|DragonFly)
install(FILES "${CMAKE_SOURCE_DIR}/share/juci.svg"
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps")
elseif(APPLE)
install(CODE "execute_process(COMMAND /usr/bin/python ${CMAKE_SOURCE_DIR}/share/set_icon_macos.py ${CMAKE_SOURCE_DIR}/share/juci.png ${CMAKE_INSTALL_PREFIX}/bin/juci)")
install(CODE "execute_process(COMMAND ${CMAKE_SOURCE_DIR}/share/set_icon.sh ${CMAKE_SOURCE_DIR}/share/juci.png ${CMAKE_INSTALL_PREFIX}/bin/juci)")
endif()
# add a target to generate API documentation with Doxygen

Loading…
Cancel
Save