• 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: 2551 <email@hidden>
  • Date: Fri, 09 Jan 2015 14:13:26 +0700


On 9 Jan 2015, at 13:51, Shane Stanley <email@hidden> wrote:

What method are you using to log it to Console?

-- 


I'm not using any method in the case of Script Editor. Just open Console.app, choose "All Messages", then "Clear Display" and run your script. Script Editor is directing the output to Console itself. 

(I don't know if its relevant, but this is on the latest developer build of Yosemite).

For the record, and in case I've not got the correct script, this is the version of your script I'm running:

use scripting additions
use framework "Foundation"

-- this where we'll store the stuff as we collect it; we could use a list, but it could get very long
set finalNSArray to current application's NSMutableArray's array()
-- make NSURL of where to start
set thePath to POSIX path of (choose folder)
set anNSURL to current application's |NSURL|'s fileURLWithPath:thePath
-- call our handler
my listURL:anNSURL inArray:finalNSArray
-- join the strings in the array, and convert it to an AS string
return (finalNSArray's componentsJoinedByString:linefeed) as text

on listURL:anNSURL inArray:finalNSArray
-- get file manager
set theNSFileManager to current application's NSFileManager's defaultManager()
-- define options to use
set enumerationOptions to current application's NSDirectoryEnumerationSkipsHiddenFiles
-- get list of items in directory, resolving directory's symlinks if necessary
set {theItems, theError} to (theNSFileManager's contentsOfDirectoryAtURL:(anNSURL's URLByResolvingSymlinksInPath()) includingPropertiesForKeys:{(current application's NSURLIsPackageKey), (current application's NSURLIsDirectoryKey), (current application's NSURLIsSymbolicLinkKey)} options:enumerationOptions |error|:(reference))
-- check we were allowed access to the folder
if theItems is missing value then
-- probably a permissions problem, so record it and return
(finalNSArray's addObject:(current application's NSString's stringWithFormat_("Folder '%@' cannot be accessed. Error: %@", anNSURL's |path|(), theError's localizedDescription())))
return
else
set theItems to theItems as list
end if
-- create lists to store results; it might be quicker to use arrays, but let's keep it simple
set theFiles to {}
set theFolders to {}
-- loop through the items
repeat with i from 1 to count of theItems
set anItem to item i of theItems
-- flag for file status
set isFile to true
-- is it a directory?
set {theResult, theValue, theError} to (anItem's getResourceValue:(reference) forKey:(current application's NSURLIsDirectoryKey) |error|:(reference))
if theValue as boolean then
-- is it a package?
set {theResult, theValue, theError} to (anItem's getResourceValue:(reference) forKey:(current application's NSURLIsPackageKey) |error|:(reference))
if not theValue as boolean then
set isFile to false
end if
end if
-- is it a symlink?
set {theResult, theValue, theError} to (anItem's getResourceValue:(reference) forKey:(current application's NSURLIsSymbolicLinkKey) |error|:(reference))
if theValue as boolean then
set isFile to false
end if
if isFile then
set end of theFiles to anItem's |path|()'s lastPathComponent()
else
set end of theFolders to anItem
end if
end repeat
-- add folder line
(finalNSArray's addObject:(current application's NSString's stringWithFormat_("Folder '%@' contains %@ files and %@ folders:", anNSURL's |path|(), count of theFiles, count of theFolders)))
-- add list of filenames
(finalNSArray's addObjectsFromArray:theFiles)
-- now do the same thing with each of the folders
repeat with i from 1 to count of theFolders
(my listURL:(item i of theFolders) inArray:finalNSArray)
end repeat
end listURL:inArray:


Best

Phil

DisplayDroid beta (a lightweight script editor and automation tool) is now available for free download. More info on sqwarq.com/displaydroid

http://applehelpwriter.com
http://sqwarq.com - apps for OS X & iOS
 _______________________________________________
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

  • Follow-Ups:
    • Re: Script that "Tells" Finder just Focuses on Finder instead of running
      • From: Shane Stanley <email@hidden>
    • Re: Script that "Tells" Finder just Focuses on Finder instead of running
      • From: Shane Stanley <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: Deivy Petrescu <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: 2551 <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: Deivy Petrescu <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Shane Stanley <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Deivy Petrescu <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Shane Stanley <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Deivy Petrescu <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Shane Stanley <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Shane Stanley <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Yvan KOENIG <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Shane Stanley <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Yvan KOENIG <email@hidden>)
 >Re: Script that "Tells" Finder just Focuses on Finder instead of running (From: Shane Stanley <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: Shane Stanley <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