• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Toggle invisible files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Toggle invisible files


  • Subject: Re: Toggle invisible files
  • From: 2551phil <email@hidden>
  • Date: Thu, 10 Nov 2016 19:19:07 +0700

And going the whole hog

Your 7 lines of ASObjC beat my 11 lines of AS for brevity, although my 11 lines come in at 423 characters, whereas yours come in at 554 (and if I sacrificed style, I could get it down to 7 lines by replacing the if…then..else with two singular `if…then` lines… :p)

Yes, I’m being tongue-in-cheek, but if I might digress…

This all reminds me of an idea I once had that it’d be fun if someone (you know, like people who want to promote their AppleScript software...) ran an annual AppleScript competition, along the lines of “best script under 10 lines that demonstrates to a non-AS user why they should learn AS’ or something like that.

I envisaged some of the more experienced members of this list as the judges, and some kind of community-donated prizes for winners and runners-up (e.g., like a license to a certain script editing application for the winner). I’m sure there’s a few other s/w developers that might be interested in promoting themselves to AppleScripters (FastScripts, Hazel, Keyboard Maestro) and who might be tempted to sponsor something. If one was a fantasist, one might even imagine that if such an idea was promoted  sufficiently and persistently, it might even encourage some new people to consider learning AS, or reengage some who’d tried it but given up.

Just a passing on a recurring thought I keep having: AS lacks a marketing department. :)


Best

P




On 10 Nov 2016, at 18:48, Shane Stanley <email@hidden> wrote:

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"


-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>

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
References: 
 >Re: Toggle invisible files (From: Nigel Garvey <email@hidden>)
 >Re: Toggle invisible files (From: 2551phil <email@hidden>)
 >Re: Toggle invisible files (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Toggle invisible files
  • Next by Date: Re: Toggle invisible files
  • Previous by thread: Re: Toggle invisible files
  • Next by thread: Re: Toggle invisible files
  • Index(es):
    • Date
    • Thread