How to programmatically access file resource forks on Snow Leopard? - resources

I was recently wondering how Mac OS X stores thumbnails of files. After some Googling, I found out that about "resource forks", a feature apparently unique to Apple's HFS file systems.
I don't really like the idea of having resource forks around, and I would like to be able to delete them. Is there any way to access the resource forks programmatically? Various forum posts said that to see the resource fork of a file like presentation.pdf I should ls presentation.pdf/rsrc, but I haven't been able to find a file like that on my system. Is this still how it works in Snow Leopard?
I am not interested in downloading or buying some tool that does this for me. I'm comfortable with the command line, and ideally I would like a command line solution, so that I can script this.
And before I actually go through with this, I guess I should ask: is there any harm in deleting the resource forks?

It depends on what is in the resource fork. The use of resource forks has been discouraged, but there are few holdouts including alias files, custom icons (on files) and some legacy font files. You can verify if a file has a resource fork in the Terminal using "ls -l#". The resource forks are also exposed in the extended attribute APIs through the "com.apple.ResourceFork" attribute.
If you want to just remove thumbnails, you could do that from the Finder's GetInfo panel. The extended attribute APIs, like removexattr(2), will let you programmatically remove the Resource Fork.
If you're curious what's inside a resource fork you can use: "hexdump -C myfile/..namedfork/rsrc"
Hope this helps
-Don

You ask - "is there any harm in deleting the resource forks?"
Of course there is. Those are files that someone has constructed to be a certain way, and if you delete chunks from them, whatever program is using them is not going to be happy. You should only do so in certain situations where you know what you're getting into.
For example, Text Clippings (what you get when you drag a chunk of selected text to the desktop) are stored entirely in the resource fork. The data fork is empty. This is annoying, but it's the way it is. If you delete the resource fork, there goes all your text.
A better approach might be to contact the author of whatever software is still creating resource forks and try to convince them to abandon that practice, because you like having everything in data forks.

Related

FPC/Lazarus component like TImageList, but for generic files?

Just like TImageList contains a collection of images, is there a similar component for generic files?
I know I can embed files as resources, but I'd like the convenience of storing different groups of files in different "TFileList" components, and to be able to retrieve files by name or by their position in the list.
Extra points if such a component allowed some sort of design time preview of the file content (just like TImageList lets you see what each image looks like, at design time).
(I come from Delphi where I wrote my own component to do the above, but before I rewrite and port the property editor and all that to Lazarus, maybe there is already something that is tried and tested...)
Thanks!
You can use pre-defined lazarus TFPGList to specialize list of the type, that you want, for example - UTF8String
But, there's no T<>List as a component, only as object.
So, yes, this feature will be useful and i can implement, if have time,
also, there's a very limited RTTI, which has been updated only a few months ago, so you can access Methods and Properties now, so FP is more systemized, than delphi pascal, but also not so enterprise-developed, which limits it to implementations for common opensource and shareware project problems.
Nevertheless, it is more stable and supported, even my friends can contribute.

Storing and retrieving files in Blockly Web

I want to use Blockly to do some calculations, and then generate text files (as opposed to exporting code to JavaScript, Python, PHP, etc.)
I can’t see an obvious way to create my own blocks to do this in Blockly, so using AppInventor (Version: nb168), I got storing and retrieving files to work, in a crude test app on my Android tablet.
In AppInventor/Designer mode, clicking Storage/File creates a “Non-visible component for storing and retrieving files. Use this component to write or read files on your device.”
Then, in AppInventor/Blocks mode, clicking the “File1” icon gives access to 7 “file type blocks”, e.g. AppendToFile, Delete, ReadFrom, SaveFile, etc.
Is it possible to create similar “file type blocks” to use in Blockly Web?
I have limited programming knowledge, so would appreciate simple answers, please.
Thanks, Pete.
Andrew N Marshall from Google/Blockly has told me this:
"This is absolutely possible ...as long as you willing to work within the browser's security restrictions. The resulting files will be need to be manually "downloaded" one at a time, rather than written directly to the user's file system.
... I would start understanding what JavaScript functions are available to you. Attempt to construct a string and save it via a download dialog...
That means the "file" contents are really just a string in memory, a JavaScript variable. We have lots of "Text" blocks that can do a variety of operations on strings. If those are enough, you'll only need one new block to identify the string variable and initiate the download process.
Otherwise, you'll need to think about what blocks you want, and how they operate. They may operate on a specific variable in the JavaScript VM, not necessary exposed as a variable to Blockly.
Either way, you'll need to learn how to create a block and a Blockly app. We have a code lab that will walk you through all the steps. You'll learn how each block generates a string of code, and in your case, that code will be related to the download code I mentioned earlier."
So I'll press on - I just wanted to be sure my goal is actually achievable before I started.
Thanks, Pete.

Use Chef to modify settings for all IIS sites running on a node

our ops team wants to make sure that all IIS web sites are (a) logging to the right place and (b) logging the right things. The most awesome IIS Cookbook allows me to do both of these things if I know what sites are running on this old box, which, sadly, I do not. So a fairly straightforward implementation could be:
list_of_sites.each do |s|
iis_site s do
log_directory 'c:/fireplace'
etc.
end
end
But ... I don't know what sites are running on a given node. Ohai doesn't seem to have this info, but maybe there is a wonderous (I like this spelling better) Ohai plugin that my google-foo couldn't find. I could write an ohai plugin for this I suppose. But it would be my first so a little reluctant to go there. Are there other options?
Good list of ways to list sites is here: Display all sites and bindings in powershell, but not sure how to use a list of sites generated by powershell from within a recipe.
We're running chef 12 and various IIS's but oldest is 7.0.
Thx for any advice!
Making an Ohai plugin for this one thing is probably overkill, I would just use powershell_out with a variant of the code you linked to. You would want something like this:
cmd = powershell_out!(<<-EOH)
# A bunch of PS code goes here
EOH
sites = some_kind_of_parsing(cmd.stdout)
sites.each do |site|
The example PS code you linked is using Format-Table which would suck to parse back out, but I bet you can find some way to output it as JSON which would be much easier, or even just a line-based table without the header lines.

Combine some CScrollView into one

I have some files and i use OpenDocumentFile() to open and get pFirtView of each file.
Now i have CView/CScrollView(s) for the files.
I need combine all CView/CScrollView(s) to only one CScrollView. Any suggestion? Thanks
The framework doesn't support this. You can probably hack around it by providing some sort of aggregate CView that can host multiple windows and does the layouting, but for your mental health, I suggest avoiding Doc/View for any scenario that is not exactly the way it is intended to be used, and do your window creation/drawing.
Remove the CDocTemplate based creation part in the App class, create a CWnd-derived class to host other windows and set m_pMainWnd to that window. That gets you there 90% of the way (well apart from the actual drawing in the child windows, of course...)

Is there an API for setting user profile icon/tile pictures for Gnome 3?

I am trying to programmatic-ally set the Gnome 3/GDM 3 user profile/tile/face picture for a user's account in Gnome3/GDM. This is my first attempt at a simple program for Linux and I'm unfamiliar with the APIs and my searching has yielded little useful information. It seems like one can write data to a .face file but this doesn't seem to take affect (or perhaps my file type/specs are wrong). I found from this forum post that the information is stored in a user-specific directory under /var/lib/AccountsService/users, however I want my program to run with regular user privileges and writing (directly) to this file would require elevated privileges (despite an unprivileged user being able to specify an image for their account via the Gnome settings GUI).
Ideally, I would like to do the same for KDE/KDM and Gnome 2 versions as well. Any information would be greatly appreciated. Thanks!
OK, here's the part I can shed some light on:
On any Unix'y OS, you can always fall back on the GECOS field update function putpwent. Traditionally, the “Real Name” is the first part of the GECOS field in the user record, up to the first ,. Different systems store different extended information after the ,, including things like department names, home and office phone numbers and the like.
In Gnome 2, “they” used to use ~/.face as your personal face icon. However, there are all kinds of situations in which one user can't look into another's home folder (including root: things like network filesystems, encrypted loopback homes, and more), so this was abandoned at some point (I believe 3.0) in favour of the /var/lib/AccountsService/icons/$YOURNAMEHERE location.
In the spirit of Gnome 3, the new system (the one you most likely want to use) is the Accounts Services DBus service. You can obtain a user object over DBus, and alter it. The interface is org.freedesktop.Accounts / org.freedesktop.Accounts.User and has methods like SetRealName and SetIconFile. There are also a “bunch” of other methods for things like location, language, eMail, …
PS: you can also use libaccountsservice to interact with it without calling the DBus yourself. EG: void act_user_set_real_name (ActUser *user,
const char *real_name) and void act_user_set_icon_file (ActUser *user,
const char *icon_file) are exported from that library.
However, I don't know if K (or which version(s) of K) might be looking at this DBus service. So, if you really want to set up the K information, I'm afraid I don't know…
For what it's worth, you can also just let the user adjust it themself with
gnome-control-center user-accounts

Resources