• 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: Script that "Tells" Finder just Focuses on Finder instead of running
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script that "Tells" Finder just Focuses on Finder instead of running


  • Subject: Re: Script that "Tells" Finder just Focuses on Finder instead of running
  • From: Shane Stanley <email@hidden>
  • Date: Sat, 03 Jan 2015 10:40:52 +1100

On 3 Jan 2015, at 9:29 am, Alex Hall <email@hidden> wrote:

Oh, two more quick things. First, given that Yosemite can do it, is there any advantage to using _javascript_ instead? I don't mean to open a can of worms with this question, but is there any reason to consider it?

If you're comfortable in _javascript_, maybe. But you're still dealing with the same object model, and that's where you're striking problems.

Right now I'm checking if "kind" is equal to "Folder" or "Alias", but is that a reliable check? Is there a better way to do it that doesn't rely on string constants, or can I trust those constants to always be the same across devices and OS changes?

Possibly not. The property you should probably use is class.

The Finder is notoriously slow, and I wouldn't use if for something like this unless you're only going to use it with small-ish folders. You mentioned shell alternatives, but they fall foul of package documents. Nevertheless, something like this should get you started:

tell application "Finder"
set currentDir to (target of front window)
set theString to my listContents(currentDir, "")
-- do something with theString
end tell

on listContents(aFolder, theString)
set subFolders to {}
tell application "Finder"
set {theClasses, theNames} to {class, name} of items of aFolder
set theCount to count of theClasses
set theString to theString & "Folder " & (name of aFolder) & " contains " & theCount & " item(s):" & linefeed
repeat with aName in theNames
set theString to theString & aName & linefeed
end repeat
set theString to theString & linefeed
-- get list of subfolders
repeat with i from 1 to count of theClasses
if item i of theClasses is folder then
set end of subFolders to alias ((aFolder as text) & item i of theNames)
end if
end repeat
end tell
-- process subfolders
repeat with aFolder in subFolders
set theString to listContents(aFolder, theString)
end repeat
return theString
end listContents


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

 _______________________________________________
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: 
 >Script that "Tells" Finder just Focuses on Finder instead of running (From: Alex Hall <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Luther Fuller <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Alex Hall <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Luther Fuller <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Alex Hall <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Alex Hall <email@hidden>)

  • Prev by Date: Re: Script that "Tells" Finder just Focuses on Finder instead of running
  • Next by Date: Re: Script that "Tells" Finder just Focuses on Finder instead of running
  • Previous by thread: Re: Script that "Tells" Finder just Focuses on Finder instead of running
  • Next by thread: Re: Script that "Tells" Finder just Focuses on Finder instead of running
  • Index(es):
    • Date
    • Thread