Green Folder on users deskotp

Tone_vil
New Contributor II

May be a silly post but I thought I post here for some ideas if any. So i been tasked to create a green colored folder on users desktop that contains "X file". I can get this working on my local system but when I package it and deploy it to another system when the folder installs on the new system the color reverts back to default. Basically it seems like the custom folder color settings don't carry over. I've tried installing the folder in a shared location then creating a colored alias still no go. I've also tried creating a custom green icon folder and trying to redirect that icon to the shared folder location but even that is proving to be challenging. has anybody ever had to tackle a silly task like this? I've been at it for a few days already maybe I'm overthinking?

1 ACCEPTED SOLUTION

dsavageED
Contributor III

Applescript is probably the most reliable way to set an icon, it aint pretty though...

#!/bin/bash

ITEM_PATH="$4"
echo "The path is $ITEM_PATH"

ICON="$8"
echo "The icon is $ICON"

AS_ICON=`echo "\"${ICON}\""`
AS_PATH=`echo "\"${ITEM_PATH}\""`
# Variable with necessary aplescript features around them
	osascript <<EOD
use framework "AppKit"

--------------------------------------------------------------------------------
# PROPERTY DECLARATIONS:
property this : a reference to current application
property NSWorkspace : a reference to NSWorkspace of this
property NSImage : a reference to NSImage of this

--------------------------------------------------------------------------------
# IMPLEMENTATION:
on run argv
  set icon to $AS_ICON
  set target to $AS_PATH

  setIcon to icon for target
end run
--------------------------------------------------------------------------------
# HANDLERS:
to setIcon to iconPath for filePath
  set sharedWorkspace to NSWorkspace's sharedWorkspace()
  set newImage to NSImage's alloc()
  set icon to newImage's initWithContentsOfFile:iconPath

  set success to sharedWorkspace's setIcon:icon forFile:filePath options:0
end setIcon
EOD
fi

View solution in original post

3 REPLIES 3

AJPinto
Honored Contributor III

I think you have to use Apple Script to change the icon for the folder after you create it as those attributes are not technically a part of the folder but more or less a customization of the user space.

dsavageED
Contributor III

Applescript is probably the most reliable way to set an icon, it aint pretty though...

#!/bin/bash

ITEM_PATH="$4"
echo "The path is $ITEM_PATH"

ICON="$8"
echo "The icon is $ICON"

AS_ICON=`echo "\"${ICON}\""`
AS_PATH=`echo "\"${ITEM_PATH}\""`
# Variable with necessary aplescript features around them
	osascript <<EOD
use framework "AppKit"

--------------------------------------------------------------------------------
# PROPERTY DECLARATIONS:
property this : a reference to current application
property NSWorkspace : a reference to NSWorkspace of this
property NSImage : a reference to NSImage of this

--------------------------------------------------------------------------------
# IMPLEMENTATION:
on run argv
  set icon to $AS_ICON
  set target to $AS_PATH

  setIcon to icon for target
end run
--------------------------------------------------------------------------------
# HANDLERS:
to setIcon to iconPath for filePath
  set sharedWorkspace to NSWorkspace's sharedWorkspace()
  set newImage to NSImage's alloc()
  set icon to newImage's initWithContentsOfFile:iconPath

  set success to sharedWorkspace's setIcon:icon forFile:filePath options:0
end setIcon
EOD
fi

Tone_vil
New Contributor II

Thank you for the reply, I'll give this a try just for my FYI. I ended up creating the custom icon then changing the icon of the folder to custom icon on my system. then I packaged it in composer to place both it in a shared location, then scripted something to copy the folder to the all the users desktop, instead of using an alias. does what I need. lol