Position Finder Icons

Is there a way to save and restore the position of icons on the desktop? It
apparently does not work through AppleScript (yalmost on OSX 10.11 and 10.12 ).
I’m hoping someone knows if Xojo can get at this either
directly or through declares or some plugin.
Thanks

I seem to recall that’s what “.DS_Store” files are for!

Unfortunately, the quest for the .DS_Store file schema is endless.

However, you can get them in AppleScript.

Using the Script Editor, you have to set the target folder frontmost and use something like:

tell application "Finder" return bounds of item "Mickey magazine 227.pdf" of front window end tell

Executing the code above will display (for my file, here): {381, 44, 445, 108}.

Now, you have to play with Xojo and Script Editor to wite the correct script for you file(s). Remember to display the target folder… front most.

You also have to deal with windoid… and other windows (like the Get Info window, the Inspector windoid and the Display settings (!) windoid: the window where you can set the folder display settigns, icon size, text location, sort by, etc.
Edit: by deal with windoid, I mean… you have to close them if any open, else your orders goes to these windows and they will not understandand you will be in trouble. In a perfect world, you have to search specificall for these windows, store their state before sending the data request and restore them once done. Easy to say that, a little bit work to write that.

I thought I heard 10.12 does not use .DS_Store files somewhere

A simple search let me think that.

However, I never was able to get more information about .DS_Store than… "this file holds information about the folder properties”… go figure. And I searched.

However I would suggest that messing with a users desktop layout may not be an idea that is accepted by many (or any)

Of course, Dave.

But, on WIndows, I saw developer moving the Mouse cursor here and there. This too is not an idea I can accept, but I do not know about the others.

That said, each of us is able to do what (s)he want with his/her destop / Mouse cursor, whatever.

In Xojo:

a. add a PushButton,
b. Add an Action Handler,
c. Put the code below:

Dim MyString As String MyString = GetFileBounds("XML data.rtf") MsgBox "Returned values: " + EndOfLine + EndOfLine + MyString

d. Put the AppleScript below in Script Editor and save it using GetFileBounds.scpt for example
e. Drag it into your Xojo project
f. run.

Doh ! I forgot the AppleScript:

on run (itemName) tell application "Finder" activate return (bounds of item itemName of front window) as string end tell end run

Nothing happens. Probably my code. Some help ?

Edit: the Finder is set to front and… nothing happens. I get the MsgBox below the front window not displaying the returned values.
I forced the returned to be string, no change.

Exsists a script doing this.
The point is: “I don’t want to use an applescript”.
So Can I use some Declares or plugin to achieve this ?
THanks

Doh (bis) ! When I closed Xojo, Firefox, I discovered an open windoid !!!

Back home, I am trying it back and… same result !

Nota: I booted on the last macOS Sierra beta… it tooks ages for Xojo to run ! *
(nice upgrade window thus [from 2015r1])

I checked and modified a bit the script to make it run fron the Script Editor: it works there.
Uncommented on run / end run, redrop in the Xojo project, run: nothing !

  • Second run, it tooks only 15 seconds to load the so low sized project.
    Nota: the Xojo folder was open, and the application was still there (in its folder, in the Application folder).

Edit: I closed the script window in the Script Editor (in case it matters).

Strange…

I commented the on run(itemName) / end run lines, forgot to uncomment them, save, re-import, run in Xojo IDE and… it works ! [LBN: it does not works. Read far below]

I get the x, y, w, y values in the MsgBox ! The used script is:

[code]
#on run (itemName)
tell application “Finder”
# Not needed, but who knows ?
activate

# Initialize the variables
set itemName to "XML data.rtf" # I forgot to comment this line :( *
set myBounds to {0, 0, 0, 0}

if item itemName of front window exists then
	# get the bounds of the selected item
	set myBounds to bounds of item itemName of front window
	
	# Make a user report
	display dialog "Hi, this is AppleScript !" & return & myBounds
else
	# Report the error
	display dialog "The target file " & itemName & " does not exists."
end if
# Return the myBounds value
return myBounds

end tell
#end run[/code]

  • Since I forgot to comment the line that set the itemName in the script, I had doubts about the results, so I commented it and get… nothing. So the question remains the same: is it possible to get the position (or bounds) of an item from the Finder ?

I had a crazy idea: what if theitemName variable is… empty ?

In the AppleScript, just below the activate line I add:

if itemName is "" then return "The itemName contents is [" + itemName + "]." else return "An error occured. itemName is empty." end if

I saved the script, deleted the one in the IDE, dropped the new version, ran the project and… I get the error display dialog. So, it is time for me to stop wasting my time.
BTW: I checked using the free Xojo 2016r3 (macOS Sierra beta 3 (last)).

Not to mention very much taboo and completely out of question in the MAS …

After some extensive searches (and tries to reject piece of nonsense all around the web), I finished by getting a short information (urban legend?): this may be true in the new OS volume format (when it will see the light of day): APFS.

I even found tricks to avoid the FInder to really create .DS_Store files in folders, every folder.
What will be the result ? each time you will open a folder in the Finder, it will be opened somewhere on the screen, displaying its contents using arbitrary (usually the last opened settings) rules, displaying the files here or there. Worst, some people develop OS patches to work-around so called Finder bugs (and sometimes the bug does not even exist excepted in the developer mind because he does not know how OS X works :frowning: and (s)he even is able to find people to believe that (s)he needs this piece of crap… go figure). And I do not talked about Urban Legends…

I think this post has gone off topic. Really I was asking to the community if someone know some Api or plugin to do what an Applescript already do.
This script , you can find an App based on this here
My request is: is It possible to achive the task using only xojo coding ?
Thanks
M

I found an hint on stackoverfolw:

[quote]NSFileManager *manager = [NSFileManager defaultManager];
[manager moveItemAtURL:oldURL toURL:newURL error:error];[/quote]
I’m not an Objective-C programmer. I think with a Declare is possible to retrive and set the position of any item into a folder…

What’s wrong with AppleScript ?

For example AppleScript is not accepted for sandboxed applications and an Apps using It are rejected from Apple Store…

WRONG. Applescript is neither impossible in a sandboxed app, nor rejected in the MAS more than shell. Curious how urban legends persist.

What may be rejected is access to the desktop or system events. For instance, using declares won’t change the fact that sandbox will not permit to click on elements of the screen through the API more than through AppleScript (although that has been deprecated in AppleScript since). I tried.

I doubt extremely much you will be able to access icons on the desktop from a MAS app, no matter the way you do it, because it is absolutely and officially off limits in the MAS. None of the elements of the desktop is available to a MAS app. I also tried to get the size and position of the dock through declares. It works great but as soon as the app is sandboxed, it stops working. And since Apple won’t give any temporary entitlement to access that, I had to give up.

More recently I created Char Menu that allows to click on a character, and see it pop in the front application as if it was typed on the keyboard. It uses RemoteControlMBS plugin. When simply digitally signed, it works great. But when sandboxed, it stops working. I had to settle for copying the character to the clipboard.

I ended up having two versions : one in the MAS that only copies, one on my own site that copies and types.

Sorry to tell you that, but it may save you wasting time on projects that will never be accepted.