Reading '.DS_Store files'

Hello. I’m trying to read the content of .DS_Store file to store it later into a database.

I’m using binary stream to read:

[code] dim b as BinaryStream
dim data as String
Try
b = BinaryStream.Open(f,false) // <–Break here, trying to open file.

data = b.Read(b.length)

if b.ReadError then
  MsgBox("Error reading")
end if

b.close

return data

catch err as IOException
MsgBox “an IO exception occurred:” + err.Message + " num: " + str(err.ErrorNumber)
end try[/code]

I got Exception numer = 2 . I see in the file properties readable is false … there is away to force reading or a workaround, maybe using Cocoa Apis ?
Thanks in advance.

  • dont mess with changing anything about a .DSTORE file… it could make Finder very upset
  • I also wouldn’t get hung on on this file, as I undertstand that Sierra and beyond won’t even have them

Sierra and beyond won’t even have them
Once the new file system will be released.

In this point of view, my concern is… do you have the .DS_Store file format ?

About your code:

You forgot to share Dim f As FolderItem

Read the whole file in a variable… is against the BinaryStream idea (b.Read(), b.ReadBoolean, b.ReadInt16, etc.).

Here the errors from your code are:

data = b.Read(b.length) return data

data is not declared. Once Dimmed, it works. The code below “works”, but how usefull is it ? And it does not let me see the invisible files.

[code] dim b as BinaryStream
dim fLen As UInt64
dim data as String
Dim f As FolderItem

f = GetOpenFolderItem(“”)

Try
b = BinaryStream.Open(f, False) // <–Break here, trying to open file.

fLen = b.length

data = b.Read(fLen)

if b.ReadError then
  MsgBox("Error reading")
end if

b.close

TA_XML.Text = data // TA_XML is a TextArea, used for simple report

catch err as IOException
MsgBox “an IO exception occurred:” + err.Message + " num: " + str(err.ErrorNumber)
end try[/code]

BTW: I forgot how to get an invisible file :frowning:

I found your… “break” !:

It is an IOException. Just because f does not exists. I added to your code:

[code] Dim f As New FolderItem

f = GetFolderItem("").Child("./DS_Store")
if f = Nil Then
MsgBox “f is Nil.”
Return True
End If

if Not f.Exists Then
MsgBox “f does not exists.”
Return True
End If[/code]

I also used (to be sure I get one .DS_Store file):

f = SpecialFolder.Documents.Child("./DS_Store")

and I get “f does not exists.”. Note that I run El Capitan :-{

I used the AppleScript below to be sure I have a .DS_Store in the target folder:

[code]tell application “Finder”
choose file with invisibles

return properties of the result

end tell[/code]

I’m on OSX El Captain too. the .DS_Store file exists.


Right code is:

[code] Dim f As New FolderItem

f = SpecialFolder.Desktop.Child(".DS_Store")

if f = Nil or Not f.Exists Then

MsgBox "f is Nil."

else

MsgBox "f exists."

End If[/code]

The IOException number 2 is due to ‘not readeable’ file

[quote=301457:@Dave S]* dont mess with changing anything about a .DSTORE file… it could make Finder very upset

  • I also wouldn’t get hung on on this file, as I undertstand that Sierra and beyond won’t even have them[/quote]
    Sierra and El Captain still have these files… the Finder will never show them …
    From

and again:

Hello,
on El Capitan I can make „.DS_Store“ files visible with the help of the application „Tinkertool“ (http://www.bresink.com/osx/TinkerTool.html).
Start Tinkertool, go to the „Finder“-tab, check „Show hidden and system files“ and press the „Relanch Finder“-button.

I do not have Sierra installed, so I do not know if this works there too.

■■■■■■■■ as many other sentences all over the internet and not only in .DS_Store cases.

As delivered, invisible files are… invisibles (in the Finder). The only way to make them visibles is to use a special software (how do it do that ?) OR to change their file name (usually removing the leading dot, but not only).

Also: you cannot add a leading dot to a file (folder) in / from the Finder: the action is rejected.

How the future will be ? Who knows. No more .DS_Store in the new macOS sile system ? Why not, but what will replace it ?

About OS changer applications
Since the old days of After Dark, (nearly 30 years ago) I stopped to use third party OS changers (like but not only: TinkerTool): they may works (from some seconds to… some OS versions), but they also can crash.

At last, showing invisible files is like displaying file (folders) extension: if you do not know what to do with them, this is useless.
Question: do you know how many invisible files there is in a macOS initialized SD-Card ?

Back to the subject:

a. Opening .DS_Store is one thing, but without its internal schema composition (what Long at $0100 means ?) you can do nothing.

b. Reading the whole file is the wrong way: use BinaryStream specific Method build to do read Long, String, etc.

Good luck.

[quote=301482:@Christian Mézes]Hello,
on El Capitan I can make „.DS_Store“ files visible with the help of the application „Tinkertool“ (http://www.bresink.com/osx/TinkerTool.html).
Start Tinkertool, go to the „Finder“-tab, check „Show hidden and system files“ and press the „Relanch Finder“-button.

I do not have Sierra installed, so I do not know if this works there too.[/quote]

In Sierra It must works the same. Our Xojo Thinkertool:

I also solved my issue. It was a path issue when going to read binary file because ‘nativepath’ mode doesn’t worked for me.
Here the working project:

@Schwartz
.DS_Store Files can be opened and manipulated…maybe not yet in xojo. There is good library to achieve this task in Python…
this is the URL . Maybe someone skilled with Python could make a xojo porting…

Thanks

That’s your opinion. I personally prefer to read the entire thing, because it is much more efficient. If you prefer to use the BinaryStream methods to pick the file apart, you can read the entire file into a MemoryBlock and open a binarystream on the memoryblock. That way, all your operations are in memory.

Either one still requires you to know the file format regardless of on disk or in memory
And since .DS_Store is in an undocumented format Apple could change it on a whim and break whatever software relies on it’s current format

Tim, Norman:
It’s OK for me: MemoryBlock have similar Read commands / File Format is undocumented AFAIK.

Invisible files:
A friend of mine have on a Windows XP a virus that hides all copied files to MemoryStick. I wrote a simple AppleScript that allows me to select the original invisible (and not the lnk file) file and copy it into my MacBook Pro to be used (a sqlite file): it is visible on OS X.
I tried to remove that virus (using a Windows script like icon), but I failed by lack of Windows knowledge.

I nearly forgot:
.DS_Store file is created only when you open the folder. Otherwise nothing is done even if you copy / move files in that folder. Windows do the same with Thumbs.db.
Why ? THere is nothing to … store in the files if the folder is not opened (or the folder is empty). This is how it works (worked).

Remember: Urban Legends exists for everything (unlike proofs, evidences). The more unknow (or undocumented),the domain is, the more Urban Legends will talk (and nearly always wrong) about. So, before writing / giving clues (links), check if this is true… or not.

I read the shared document about .DS_Store (http://ds-store.readthedocs.io/).

A tuple seems to be an enum (for us Xojo developer and some others like C…)

The pdf document is very scarce about the .DS_Store file format, but until a real run of code, it will still be that. Maybe running the code reveal some useful result.

But now, we know the next Apple file system (APFS) will not use .DS_Store files, how useful is this ?

ars technica: The ars technica macOS Sierra review . We have to wait until sometimes in 2017 to get it on our computers.

Carlo:

in your example, instead of returning the .DS_Store contents as string in the TextArea, try storing the data as Hex / ASCII like:

$0000 00 00 00 01 42 75 64 31 00 00 10 00 00 00 08 00 ....Bud1........ $0010 00 00 10 00 00 00 00 87 00 00 00 00 00 00 00 00 ................ $0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 ................ $0030 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ $0040 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 01 ................ $0050 00 00 00 01 00 00 10 00 00 2E 00 64 00 65 00 73 ...........d.e.s $0060 00 6B 00 74 00 00 00 00 00 00 00 00 00 00 00 00 .k.t............ $0070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ $0080 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 1E ................ $0090 00 74 00 65 00 73 00 74 00 2E 00 64 00 65 00 73 .t.e.s.t...d.e.s $00A0 00 6B 00 74 00 6F 00 70 00 2E 00 69 00 63 00 6F .k.t.o.p...i.c.o $00B0 00 6E 00 2E 00 70 00 6F 00 73 00 69 00 74 00 69 .n...p.o.s.i.t.i $00C0 00 6F 00 6E 00 2E 00 7A 00 69 00 70 49 6C 6F 63 .o.n...z.i.pIloc $00D0 62 6C 6F 62 00 00 00 10 00 00 00 55 00 00 00 4C blob.......U...L

You will be able to understand faster what is in the file. For example:

$0000: 00 00 00 01: # of description file(s)
$0014: 00 00 00 87 : adress of the file name (LString)
$00D0: 62 6C 6F 62 00 00 00 10 00 00 00 F9 00 00 00 4C blob…L
00 00 00 F9 and 00 00 00 4C are the x,y item position
position: {249, 76} [this comes from a Script]

Nota: the first space after the file position ($0000), is a Tab, while because of the strange TextArea implementation, I had to place a space between the Hex and ASCII parts ( a tab there moves the remainding of the paragraph in the next line (: ).

In what you report in the TextArea are descriptions I saw in a Preferences plist (com.apple.finder something). Phis plist can be opened using XCode.

The Hex / ASCII above comes from a .DS_Store stored in a folder with a single file (your project as zip).

@Christian Smith
In your file manager class does exists this ?

NSFileManager *manager = [NSFileManager defaultManager]; [manager moveItemAtURL:oldURL toURL:newURL error:error];