Re: Toggle invisible files
Re: Toggle invisible files
- Subject: Re: Toggle invisible files
- From: Shane Stanley <email@hidden>
- Date: Thu, 10 Nov 2016 22:48:30 +1100
On 10 Nov. 2016, at 10:38 pm, 2551phil <email@hidden> wrote:
As Shane’s already pointed out, that setting can also be ‘Yes’ or ‘True’, so just testing for ‘1’ won’t cut it.
FWIW, the Cocoa method for getting the boolean value of a string, which we can assume is used here, works like this:
This property is YES on encountering one of "Y", "y", "T", "t", or a digit 1-9—the method ignores any trailing characters. This property is NO if the receiver doesn’t begin with a valid decimal text representation of a number. The property assumes a decimal representation and skips whitespace at the beginning of the string. It also skips initial whitespace characters, or optional -/+ sign followed by zeroes.
Not that you're likely to find such things here, I hope...
Anyway, here's an ASObjC alternative, which actually sets the value to <true/> or <false/>:
use AppleScript version "2.4" -- Yosemite (10.10) or later use framework "Foundation" use scripting additions
set theDefs to current application's NSUserDefaults's alloc()'s initWithSuiteName:"com.apple.finder" theDefs's setBool:(not (theDefs's boolForKey:"AppleShowAllFiles")) forKey:"AppleShowAllFiles"
Or as a one-liner:
tell (current application's NSUserDefaults's alloc()'s initWithSuiteName:"com.apple.finder") to setBool:(not (its boolForKey:"AppleShowAllFiles")) forKey:"AppleShowAllFiles"
And going the whole hog:
use AppleScript version "2.4" -- Yosemite (10.10) or later use framework "Foundation" use framework "AppKit" use scripting additions
tell (current application's NSUserDefaults's alloc()'s initWithSuiteName:"com.apple.finder") to setBool:(not (its boolForKey:"AppleShowAllFiles")) forKey:"AppleShowAllFiles" (current application's NSRunningApplication's runningApplicationsWithBundleIdentifier:"com.apple.finder")'s firstObject()'s forceTerminate() current application's NSWorkspace's sharedWorkspace()'s launchApplication:"Finder"
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden