Detect App Translocation

Is there a relatively foolproof way to detect if your app is running with translocation? I believe the 10.12 SDK has new calls, and there’s some ObjectiveC code for detecting it w/o using the 10.12 SDK: https://lapcatsoftware.com/articles/detect-app-translocation.html

Has anyone done this in pure Xojo code?

My use case: I have a code-signed app which looks for user-edited data in a folder next to the app. Rather than failing to find the files when translocated, I’d rather detect this and let the user know what to do (move the app to another folder then relaunch).

I’m going to tell you that there are countless admonitions on this forum not to do this, then you will tell me why it’s essential for your app.

Actually, I’m going to ask politely for people posting in this thread to stay on topic.

I can imagine a few ways but I’m interested in anyone has working code:

  • using the 10.12 SDK above
  • using GetFolderItem(“”) and looking for a wacky path name
  • using xattr to check for the quarantine bit

Rogers response was very much on topic… Storing data “next to the app” is not a good idea, for many reasons, translocation being the latest one. But of course, like all suggestions offered on this forum, you are free to accept, or reject…

That being said… looks like you answered your own question…

Personally, I am using declares to get to the bundle path (I think the code is in Timi’s Special Folder module), then checking that for a wacky path; sorry I’m at wrong computer so I can’t see exactly how I did it.

Thanks, Sam - I can probably work out that solution myself (I guess it depends on just how one defines “wacky”).

I’m doing some tests, and I’m wondering if I don’t understand translocation fully?

I have a Xojo app, code signed. It’s zipped (along with a data folder) and put on a website. A user downloads the zip file, unzips the files, then double clicks the app.

  • On 10.11 it “just works” (because 10.11 doesn’t have translocation).
  • On 10.12 or 10.13, it fails (can’t find the data folder). This is my understanding of Translocation working.

However,

  • On 10.12 or 10.13, the user moves the app and data folder to a new location (say, “Desktop”). They double click the app.
  • In some situations it’s working (presumably because moving the app to a new location stops translocation?)
  • In some situations it’s still failing though. I thought moving the app was the magic that turned off translocation? Is there some “gotcha” here?

Sure, this is perhaps true in general, but it is not universal. There are a number of situations (many of which were hashed out in prior discussions) in which storing the data next to the app is actually a really good idea.

In my case, a bespoke non-commercial app for testing, that will ultimately be stored on thumb drives (for technical and policy reasons), to be used by a small number of non-technical folks, with approximately zero budget and even less time.

My path of least resistance: get it working on 10.12 and later like it did for 10.11 and earlier (and also to let the user know what’s wrong and how to fix it when it’s broken).

[quote=379825:@Michael Diehr]

  • In some situations it’s still failing though. I thought moving the app was the magic that turned off translocation? Is there some “gotcha” here?[/quote]

On further testing, I think the problem was that the app was still open and running when I tried to move it. More careful testing seems to work as expected: if you move the app after unzipping, translocation is disabled.

Surely for YOU the issue is not really translocation but ‘where is my data folder?’

If the folder has to be in the same folder as the app (it really doesnt, off topic or no), they could be separated by moving the app alone, the folder alone, or possibly translocation.

Sorry but:
If the folder is in specialfolder.applicationdata
then you app works no matter where it has been placed.

…Leaving you to work out ‘has it been translocated?’ (if you want to)

I check to see if ‘Applications’ is in the path. If it is not, I ask the user to move the app there, and translocation is sorted.

GetFolderItem("", FolderItem.PathTypeShell) will show something else than /Applications.

I tested that quite a while ago when translocation came to be.

if left( app.executableFile.nativePath, 9 ) = "/private/" then rvalue.append "?? Translocated"

Couldn’t you just hardcode in the name of the thumbdrive, or search all available disks to find a pattern that matches what you expect and then read/write the data from there? Then the application will never need to be copied to the users machine.

[quote]On further testing, I think the problem was that the app was still open and running when I tried to move it. More careful testing seems to work as expected: if you move the app after unzipping, translocation is disabled.
[/quote]

Correction: more testing of Translocation reveals some some complexity with the “move app to another folder to disable translocation” feature.

These tests were conducted on 10.12.6 and consist of an App (properly codesigned with my Apple Developer ID) + Data folder in a Zip archive, downloaded from a web server using Safari. The zip file is then unzipped and tested (by first taking an action listed below, then double-clicking the App icon) to see if it’s translocated.

Situations in which Translocation is Enabled (as reasonably expected)

  • Launched from within the unzipped folder.
  • Rename the app in the unzipped folder
  • Duplicate the app in the unzipped folder

Situations in which Translocation is Disabled (as expected):

  • Drag move the App to the Desktop, then drag move the Data folder to the desktop (two separate steps)
  • Copy the app to the Desktop, then Copy the Data folder to the desktop (two separate steps)

Situations in which Translocation remains Enabled which may not be expected:

  • Drag move both the App and the Data folder to the desktop in one step
  • Drag copy (holding the Option key) both the App and the Data folder to the desktop in one step
  • Copy & paste App + Data folder to the Desktop in one step
  • Drag move (or drag copy w/option key) the parent folder (containing both the App and Data folder) to the Desktop

These quirks are now making me rethink the idea of giving my end-users a simple instruction such as “move the app and data folder to a new location” as their success will depend on the specific method they used.

Note: under the hood, it seems like the rule is “Copy or Move App alone --> Translocation OFF”. “Copy or Move App plus any other file in one step --> Translocation ON”. In other words, it is the the App which remains quarantined (rather than, say, the Data folder).

The best way to handle those complexities for your end users is to package the files into a DMG (rather than a ZIP) and code sign that DMG as well.

That is how the Xojo installation is set up.
Probably also best to also follow the Xojo approach of placing all of your data folders and your application into a parent folder. That way the user only has one folder to copy out of the DMG.

Ultimately, the issue is “make it work”. Additional constraints are: using thumb drives, inexperienced users, and (I forgot to mention this earlier) to have similar functionality on a mixed group of Mac/Win machines.

Sure, but we’ve already trained users to not do that.

Not a bad suggestion, but for policy reasons, data needs to be stored on the thumb drives, not on the boot drive.

[quote=379834:@Jeff Tullin]
[…]I check to see if ‘Applications’ is in the path. If it is not, I ask the user to move the app there, and translocation is sorted.[/quote]

See my above post - “move the app” is not as simple as it seems.

[quote=379940:@Jared Feder]The best way to handle those complexities for your end users is to package the files into a DMG (rather than a ZIP) and code sign that DMG as well.
That is how the Xojo installation is set up.
Probably also best to also follow the Xojo approach of placing all of your data folders and your application into a parent folder. That way the user only has one folder to copy out of the DMG.[/quote]

This intrigues me and I know how to make DMGs - does copying App+Data folders from a code-signed DMG avoid the Translocation penalty in a way that’s different from zip files?

Yes, I believe that the difference is that after you code sign the DMG, the contents are no longer subject to change (since that would break the signature in the same way as changing an application bundle).

In that way, you are telling the OS that the contents of the DMG (not just the application bundle) have been blessed by the developer and can be trusted.

Give it a try.

Also, if you are looking for an easy way to see if your application is running in a translocated location (and don’t already know this trick), you can open Activity Monitor, select your application, click the “i” in the upper left to view information, then select the Open Files and Ports tab. If you see paths containing “/AppTranslocation/” instead of the expected location of your application, then you know that it has been translocated.

It’s a bit off topic, but something you might want to watch for: 10.13 (High Sierra) has a System Preferences option to store the user’s Desktop and the Documents folder in iCloud. They look to the user like they’re local, but they’re actually in iCloud. I’ve had users who had their data files on the desktop experience problems similar to what happens when a file is on Dropbox (sporadic inability to read/write, etc.). Turning off this iCloud feature got things working again (it’s on by default after an upgrade). So putting your app and its data on the desktop might or might not be safe or may not have the path you expect. I haven’t upgraded to 10.13 yet, YMMV.

I created a code-signed DMG (using https://c-command.com/dropdmg/ ) and this appears to solve my immediate issues: from the DMG, you can immediately launch the App (if you wish) or you can copy the App and Data folders to another location and Translocation appears to be inhibited, no matter how you do the copy.

An additional benefit of the DMG is that you can add fancy features such as a click-through license, ReadMe file, and even put text instructions “Drag this file from here to there” etc. in the background image of the DMG itself.

I have one customer who seems to be translocated repeatedly.
The app is in Applications
There is a user data folder in Documents
And the user data ‘vanishes’ from the apps point of view. We can see the folder in Documents using Finder, but the app cant see it.

Copy the app, paste to desktop.
Delete original
Copy the app and paste into Applications - bing - It can see the data
2 days later it can’t again.

Whats going on?