Differences in Applescript functions between different system versions - applescript

My Applescript code outputs different results under different operating system versions.
Under the system of 10.13.6
10.13.6 Image order changed!!!
Under the system of 10.11.6
10.11.6 Image
The order of 10.13.6 has changed, this is definitely a disaster, because I need to rename it according to his order.I want to know what caused this order change.please kindly advise.

The problem is a faulty assumption on your part. macOS file system APIs do not, and never have, guaranteed to return file names in a particular order. Even experienced Mac developers make this mistake. The old HFS+ file system may have ordered directory contents alphabetically, but APFS leaves it up to the client software. Either use an app that returns file names in sorted order, use a sorting routine to sort them yourself, or rework your script so it can process file names in any order.

I wouldn't use list folder at all.
System Events or Finder sort the files properly
tell application "System Events"
name of disk items of folder "Macintosh HD:Path:to:my:folder:"
end tell

Related

Default location for configuration files - MacOS?

In a cross-platform application, I am working with a configuration file that allows the user to override various defaults if he wishes to.
The problem I have is... where to place / look for this configuration file, especially with regards to MacOS X (which I never used and have no access to)? I know that MacOS X is based on Unix, but I also know that many things are done very much differently there...
My current choices:
Unix:
~/.config/<appname>/<appname>.cfg
Windows (shomewhat unsure about this one too, things seem to be all over the place here - %LOCALAPPDATA% or %USERPROFILE% seem to be valid choices too):
%APPDATA%/<appname>/<appname>.cfg
MacOS:
...?
Any comments, on MacOS or my other choices?
I think it must be ~/Library/Application Support/<appname>/<appname>.cfg
See the table in Mac App Programming Guide : "The Mac Application Environment" -> "Low-Level Details of the Runtime Environment" -> "The File System".
You can store it in the same manner you show for Unix/Linux above.
~ works the same way for home directories on OS X as UNIX platforms. Same goes for . in names for hidden directories.
Given the cross-platform needs you describe, I would do it exactly the same way on OS X as in your UNIX example.

Mac OS X and Testing Applications on Case Sensitive File Systems

I have two MacBook Pros, but they shipped with a case-insensitive file systems. I would like to test a few of my utilities on a case-sensitive file system. Is there anyway to turn case-sensitivity on per application? Perhaps there is another solution that does not require a re-format of the hard drive?
I also read Technical Note TN2096: Debugging Case-Sensitivity Bugs in Applications. But it does not detail how to set up a test environment.
There is no way to "turn on case-sensitivity" for a single application. The filesystem structure on your volume is what's case-sensitive or not.
You can use Disk Utility to set this up, in a couple of different ways:
If you're just testing reading and writing files: make a disk image, using the format "Mac OS Extended (Case-sensitive, Journaled)". Mount that disk image and make your app use it.
If you want to test on a system booted from a case-sensitive filesystem: add a partition to your drive, choose the case-sensitive format for the new partition, then install OS X on it. Or use an external disk.
I'm sure there are more tricky ways, but those should get you started.

How to determine whether a file or folder is hidden in Mac OS X?

How to determine whether a file or folder is hidden in Mac OS X, like we have GetFileAttributes in Windows?
See Is the file hidden?
(The matter is complicated because there are multiple factors that can cause a file to be "hidden" - the Launch Services approach described in the linked post ought to cover all of them.)

Is there something like filter driver for Mac OS X?

Windows lets you develop a filter driver to catch file I/O's on VFS. But I can't seem to find something similar for Mac. It does have something called Filter Schemes, but those are for HFS+. Anyone know if there is a way for me to intercept file I/O's on Mac without using programs like MacFUSE?
I found out that Mac OS X does not allow filter drivers at all.
“A stacking file system (sometimes called a filter file system) sits on top of another file system and modifies its behavior in some way. The canonical example of a stacking file system is an encryption file system. You could stack this file system on top of any existing file system to provide encryption support. Apple does not support the development of stacking VFS plug-ins on Mac OS X” (http://developer.apple.com/mac/library/qa/qa2001/qa1242.html)
kauth (introduced in OS X 10.4) is the closest thing to FS filter drivers.
Here is a nice write-up on the various APIs present on Mac OS X. It should be a good starting point.
Link
I'm not at all familier with the Windows technologies that you mention, but it sounds like you might be looking for FSEvents.
http://developer.apple.com/mac/library/documentation/Darwin/Conceptual/FSEvents_ProgGuide/Introduction/Introduction.html
The file system events API provides a
way for your application to ask for
notification when the contents of a
directory hierarchy are modified. For
example, your application can use this
to quickly detect when the user
modifies a file within a project
bundle using another application.
It also provides a lightweight way to
determine whether the contents of a
directory hierarchy have changed since
your application last examined them.
For example, a backup application can
use this to determine what files have
changed since a given time stamp or a
given event ID.
You should read this document if your
application works with a large number
of files—particularly if your
application works with large
hierarchies of files.

What's the minimum version of OS X that supports File System Events?

I'd like to use FSEvents aka File System Events to listen to changes to the contents of a folder hierarchy. In my tests, File System Events does a superb job. However I can't find info as to whether it works on Tiger.
Anyone know?
The header files usually know best
alt text http://img.skitch.com/20091026-g73ppybjtif46wtmjwptn4sxhi.png

Resources