Skip to main content
added 291 characters in body
Source Link
NSGod
  • 2.9k
  • 17
  • 15

I just want to add some information about what's happening.

When you copy and paste a custom icon onto a file in the Finder, what happens is the following:

  1. An 'icns' resource with resource ID kCustomIconResource (-16455) is written to the resource fork of the file in question.
  2. The Finder sets the kHasCustomIcon bit in the HFS+ FileInfo.finderFlags info for the file in question.

Both of those things must be done to establish a custom icon. You mentioned that each time you re-pasted the custom icon onto the .scpt file, its file size increased. What that tells me is that the original custom icon 'icns' resource is still in place in the file after Script Debugger saves it, but what's most likely happened is that the kHasCustomIcon bit for the file has gotten lost. When you copy and paste a new icon onto the file it adds another icns entry in the resource fork and also sets that kHasCustomIcon bit so it registers as having a custom icon.

The best solution to this problem would simply be to restore the kHasCustomIcon bit for the file rather than re-pasting a whole new icon. This should keep the file size the same.

Here is a look at the com.apple.FinderInfo for a script that has a custom icon:

user@MacBookPro15 ~ % xattr -lx /Users/mdouma46/Documents/Scripts/Leaf\ to\ HTML.scpt 
com.apple.FinderInfo:
00000000  6F 73 61 73 54 6F 79 53 04 00 00 00 00 00 00 00  |osasToyS........|
00000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000020

You'll notice that first is osas, which is the HFS+ file type, then ToyS, which is the HFS+ creator code of Script Editor. That makes up the following in hexadecimal:

6F 73 61 73 54 6F 79 53 04
o  s  a  s  T  o  y  S  

Notice that trailing 04? That's the custom icon bit being set.

If you have an existing script with a custom icon, save a copy of it that you won't edit to use as a source of "good" com.apple.FinderInfo info. You can copy the com.apple.FinderInfo from one file to another using xattr like the following:

xattr -wx com.apple.FinderInfo "`xattr -px com.apple.FinderInfo /path/to/example/file`" /path/to/file/to/fix

EDIT: I've just confirmed that this is indeed what's happening as I can see in ResKnife. There are duplicate icns entries, one for each time you paste a custom icon resource onto the file:

enter image description here

I just want to add some information about what's happening.

When you copy and paste a custom icon onto a file in the Finder, what happens is the following:

  1. An 'icns' resource with resource ID kCustomIconResource (-16455) is written to the resource fork of the file in question.
  2. The Finder sets the kHasCustomIcon bit in the HFS+ FileInfo.finderFlags info for the file in question.

Both of those things must be done to establish a custom icon. You mentioned that each time you re-pasted the custom icon onto the .scpt file, its file size increased. What that tells me is that the original custom icon 'icns' resource is still in place in the file after Script Debugger saves it, but what's most likely happened is that the kHasCustomIcon bit for the file has gotten lost. When you copy and paste a new icon onto the file it adds another icns entry in the resource fork and also sets that kHasCustomIcon bit so it registers as having a custom icon.

The best solution to this problem would simply be to restore the kHasCustomIcon bit for the file rather than re-pasting a whole new icon. This should keep the file size the same.

Here is a look at the com.apple.FinderInfo for a script that has a custom icon:

user@MacBookPro15 ~ % xattr -lx /Users/mdouma46/Documents/Scripts/Leaf\ to\ HTML.scpt 
com.apple.FinderInfo:
00000000  6F 73 61 73 54 6F 79 53 04 00 00 00 00 00 00 00  |osasToyS........|
00000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000020

You'll notice that first is osas, which is the HFS+ file type, then ToyS, which is the HFS+ creator code of Script Editor. That makes up the following in hexadecimal:

6F 73 61 73 54 6F 79 53 04
o  s  a  s  T  o  y  S  

Notice that trailing 04? That's the custom icon bit being set.

If you have an existing script with a custom icon, save a copy of it that you won't edit to use as a source of "good" com.apple.FinderInfo info. You can copy the com.apple.FinderInfo from one file to another using xattr like the following:

xattr -wx com.apple.FinderInfo "`xattr -px com.apple.FinderInfo /path/to/example/file`" /path/to/file/to/fix

I just want to add some information about what's happening.

When you copy and paste a custom icon onto a file in the Finder, what happens is the following:

  1. An 'icns' resource with resource ID kCustomIconResource (-16455) is written to the resource fork of the file in question.
  2. The Finder sets the kHasCustomIcon bit in the HFS+ FileInfo.finderFlags info for the file in question.

Both of those things must be done to establish a custom icon. You mentioned that each time you re-pasted the custom icon onto the .scpt file, its file size increased. What that tells me is that the original custom icon 'icns' resource is still in place in the file after Script Debugger saves it, but what's most likely happened is that the kHasCustomIcon bit for the file has gotten lost. When you copy and paste a new icon onto the file it adds another icns entry in the resource fork and also sets that kHasCustomIcon bit so it registers as having a custom icon.

The best solution to this problem would simply be to restore the kHasCustomIcon bit for the file rather than re-pasting a whole new icon. This should keep the file size the same.

Here is a look at the com.apple.FinderInfo for a script that has a custom icon:

user@MacBookPro15 ~ % xattr -lx /Users/mdouma46/Documents/Scripts/Leaf\ to\ HTML.scpt 
com.apple.FinderInfo:
00000000  6F 73 61 73 54 6F 79 53 04 00 00 00 00 00 00 00  |osasToyS........|
00000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000020

You'll notice that first is osas, which is the HFS+ file type, then ToyS, which is the HFS+ creator code of Script Editor. That makes up the following in hexadecimal:

6F 73 61 73 54 6F 79 53 04
o  s  a  s  T  o  y  S  

Notice that trailing 04? That's the custom icon bit being set.

If you have an existing script with a custom icon, save a copy of it that you won't edit to use as a source of "good" com.apple.FinderInfo info. You can copy the com.apple.FinderInfo from one file to another using xattr like the following:

xattr -wx com.apple.FinderInfo "`xattr -px com.apple.FinderInfo /path/to/example/file`" /path/to/file/to/fix

EDIT: I've just confirmed that this is indeed what's happening as I can see in ResKnife. There are duplicate icns entries, one for each time you paste a custom icon resource onto the file:

enter image description here

Source Link
NSGod
  • 2.9k
  • 17
  • 15

I just want to add some information about what's happening.

When you copy and paste a custom icon onto a file in the Finder, what happens is the following:

  1. An 'icns' resource with resource ID kCustomIconResource (-16455) is written to the resource fork of the file in question.
  2. The Finder sets the kHasCustomIcon bit in the HFS+ FileInfo.finderFlags info for the file in question.

Both of those things must be done to establish a custom icon. You mentioned that each time you re-pasted the custom icon onto the .scpt file, its file size increased. What that tells me is that the original custom icon 'icns' resource is still in place in the file after Script Debugger saves it, but what's most likely happened is that the kHasCustomIcon bit for the file has gotten lost. When you copy and paste a new icon onto the file it adds another icns entry in the resource fork and also sets that kHasCustomIcon bit so it registers as having a custom icon.

The best solution to this problem would simply be to restore the kHasCustomIcon bit for the file rather than re-pasting a whole new icon. This should keep the file size the same.

Here is a look at the com.apple.FinderInfo for a script that has a custom icon:

user@MacBookPro15 ~ % xattr -lx /Users/mdouma46/Documents/Scripts/Leaf\ to\ HTML.scpt 
com.apple.FinderInfo:
00000000  6F 73 61 73 54 6F 79 53 04 00 00 00 00 00 00 00  |osasToyS........|
00000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
00000020

You'll notice that first is osas, which is the HFS+ file type, then ToyS, which is the HFS+ creator code of Script Editor. That makes up the following in hexadecimal:

6F 73 61 73 54 6F 79 53 04
o  s  a  s  T  o  y  S  

Notice that trailing 04? That's the custom icon bit being set.

If you have an existing script with a custom icon, save a copy of it that you won't edit to use as a source of "good" com.apple.FinderInfo info. You can copy the com.apple.FinderInfo from one file to another using xattr like the following:

xattr -wx com.apple.FinderInfo "`xattr -px com.apple.FinderInfo /path/to/example/file`" /path/to/file/to/fix