Posted By


kray on 10/03/06

Tagged


Statistics


Viewed 57 times
Favorited by 0 user(s)

SetDockIconVisibility (RB)


/ Published in: Other
Save to your folder(s)

Shows how to hide an icon in the Dock by manipulating the app's pList.


Copy this code and paste it in your HTML
  1. Sub SetDockIconVisibility(TheApp as FolderItem, Visibility as Boolean)
  2.  
  3. dim rf as resourceFork
  4. dim s as String
  5. dim HideIconString as String = "<key>NSUIElement</key>" + chr(13) + _
  6. "<string>1</string>" + chr(13)
  7. dim iInsertBefore as Integer
  8.  
  9. if TheApp = nil or (not TheApp.exists) or TheApp.MacType <> "APPL" then
  10. MsgBox "Application Error." + EndOfLine + EndofLine + _
  11. "Sorry, there was an error accessing the application."
  12. return
  13. end if
  14.  
  15. rf = TheApp.OpenResourceFork
  16. if rf <> nil then
  17. s = rf.GetResource("plst", 0)
  18. else
  19. MsgBox "Error opening resource." + EndOfLine + EndofLine + _
  20. "The application may be running."
  21. rf.Close
  22. return
  23. end if
  24.  
  25. if InStr(s, HideIconString) <> 0 and Visibility = true then
  26. s = ReplaceAll(s, HideIconString, "") // get rid of the line that hides the dock icon
  27. rf.AddResource(s, "plst", 0, "")
  28. elseif InStr(s, HideIconString) = 0 and Visibility = false then
  29. iInsertBefore = InStr(s, "</dict>" + chr(13) + "</plist>")
  30. If iInsertBefore = 0 then
  31. rf.Close
  32. MsgBox "Unexpected Error." + EndOfLine + EndofLine + _
  33. "Couldn't locate the end of the dictionary and the property list."
  34. return
  35. end if
  36. s = left(s, iInsertBefore - 1) + HideIconString + mid(s, iInsertBefore)
  37. rf.AddResource(s, "plst", 0, "")
  38. end if
  39.  
  40. rf.Close
  41.  
  42. rf = TheApp.OpenResourceFork // see if we really wrote to it by closing and reopening it
  43. if rf <> nil then
  44. if rf.GetResource("plst", 0) <> s then
  45. MsgBox "Error saving resource." + EndOfLine + EndofLine + _
  46. "The application may be running."
  47. rf.Close
  48. return
  49. end if
  50. end if
  51. rf.close
  52.  
  53. End Sub

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.