Tuesday, September 29, 2020

#1 2020-09-14 11:48:50 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 399

Sometimes its useful to know information about file...

Sometimes its useful to know information about files... [Automator]

The code itself don't do anything but it could be useful for debugging a workflow.

This example show 2 things.

1. It will show 'info for' with single selection or multi selection of finder items.
2. It will output a list from alias to POSIX path.

The code have been tested with this workflow in Automator.

[Get Selected Finder Items]
[Run AppleScript]

Copy the code to Run AppleScript Action

Applescript:

on run {input, parameters}
   set theList to {}
   -- Alias to POSIX path
   repeat with i from 1 to (count input)
       set (item i of input) to POSIX path of (item i of input)
       copy item i of input to end of theList
   end repeat
   
   -- Get info for of the input.
   set propertyList to {}
   repeat with i from 1 to (count theList)
       set theInfo to info for (item i of theList)
       copy theInfo to end of propertyList
   end repeat
   
   -- [Alias to POSIX path list]
   -- return theList
   
   -- [Property of info for on all items]
   -- return propertyList
   
   set theNameList to {}
   repeat with i from 1 to (count propertyList)
       tell item i of propertyList
           set theName to get its name
           copy theName to end of theNameList
       end tell
   end repeat
   -- Get the name of every input items
   return theNameList
end run

The info for give us some clue... we could use name extension and ask how many PDF
files are in our selections from Finder.

The code below inside the run handler use ASOC

Applescript:

set theNameExtensionList to {}
   repeat with i from 1 to (count propertyList)
       tell item i of propertyList
           set theName to get its name extension
           copy theName to end of theNameExtensionList
       end tell
   end repeat
   
   -- lets count every PDF of the selection and return a number
   set theCountSet to current application's NSCountedSet's alloc()'s initWithArray:theNameExtensionList
   theCountSet's countForObject:"pdf"

Last edited by Fredrik71 (2020-09-14 01:09:41 pm)


I could teach you to cook but I couldn't do anything if you do not have desire or commitment for it.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)