• 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: File-Info as Text
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: File-Info as Text


  • Subject: Re: File-Info as Text
  • From: Christopher Stone <email@hidden>
  • Date: Mon, 15 Jun 2015 00:36:35 -0500

On Aug 16, 2014, at 15:33, Christopher Stone <email@hidden> wrote:
For a while now I've been meaning to write a file-info script to grab the info I want as text and make it easy to grab any of the bits I want.
______________________________________________________________________

Hey Folks,

I've updated my info-for script a bit to include the file-URL and metadata.

As usual it depends upon the Satimage.osax for regular _expression_ support and other useful features.

Shane's alternative script still provides more information, and I'll probably incorporate some of that when I finally make the update to Yosemite or El Capitan (soonish).

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------

Output:

-------------------------------------------------------------------------------------------
Name                 :  Selection { File-Info }.scptd
Path HFS             :  Ryoko:Users:chris:Library:Scripts:Applications:Finder:Selection { File-Info }.scptd:
Path HFS Relative    :  ((path to scripts folder as text) & "Applications:Finder:Selection { File-Info }.scptd:")
Path Posix           :  /Users/chris/Library/Scripts/Applications/Finder/Selection { File-Info }.scptd/
Path Posix-Home      :  ~/Library/Scripts/Applications/Finder/Selection { File-Info }.scptd/
Path File-URL        :  file:///Users/chris/Library/Scripts/Applications/Finder/Selection { File-Info }.scptd
Creation Date        :  date Sunday, June 14, 2015 at 23:27:36 CDT  »  2015/06/14 23:27:36
Modification Date    :  date Monday, June 15, 2015 at 00:23:32 CDT  »  2015/06/15 00:23:32
Size                 :  96840
Folder               :  true
Alias                :  false
Package Folder       :  true
Visible              :  true
Extension Hidden     :  true
Name Extension       :  scptd
Displayed Name       :  Selection { File-Info }.scptd
Default Application  :  Ryoko:Applications:Applications_Chris:Developer_Tools:Applescript_Tools:Script Debugger:Script Debugger.app
Kind                 :  Compiled OSA Script Bundle
Short Version        :  1.0
Long Version         :  missing value
Bundle Identifier    :  com.mycompany.Selection---File-Info--
File Type            :  BNDL
File Creator         :  ????
Type Identifier      :  com.apple.applescript.script-bundle
Busy Status          :  false
-------------------------------------------------------------------------------------------
kMDItemCFBundleIdentifier      = "com.mycompany.Selection---File-Info----Autosaved-"
kMDItemContentCreationDate     = 2015-06-15 04:27:36 +0000
kMDItemContentModificationDate = 2015-06-15 05:23:32 +0000
kMDItemContentType             = "com.apple.applescript.script-bundle"
kMDItemContentTypeTree         = (
    "com.apple.applescript.script-bundle",
    "com.apple.bundle",
    "public.directory",
    "public.item",
    "com.apple.package"
)
kMDItemDateAdded               = 2015-06-15 05:23:32 +0000
kMDItemDisplayName             = "Selection { File-Info }.scptd"
kMDItemFSContentChangeDate     = 2015-06-15 05:23:32 +0000
kMDItemFSCreationDate          = 2015-06-15 04:27:36 +0000
kMDItemFSCreatorCode           = "????"
kMDItemFSFinderFlags           = 16
kMDItemFSHasCustomIcon         = (null)
kMDItemFSInvisible             = 0
kMDItemFSIsExtensionHidden     = 1
kMDItemFSIsStationery          = (null)
kMDItemFSLabel                 = 0
kMDItemFSName                  = "Selection { File-Info }.scptd"
kMDItemFSNodeCount             = 1
kMDItemFSOwnerGroupID          = 20
kMDItemFSOwnerUserID           = 501
kMDItemFSSize                  = 96840
kMDItemFSTypeCode              = "DLBN"
kMDItemKind                    = "Compiled OSA Script Bundle"
kMDItemLogicalSize             = 96840
kMDItemPhysicalSize            = 114688
kMDItemSupportFileType         = (
    MDSystemFile
)
kMDItemUserTags                = (
    Applescript
)
-------------------------------------------------------------------------------------------

Script:

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2014/08/15 20:04
# dMod: 2015/06/15 00:20
# Appl: Finder, BBEdit
# Task: Send Info for the selected item as text to BBEdit
# Osax: Satimage.osax { http://tinyurl.com/dc3soh }
# Tags: @Applescript, @Script, @Finder, @BBEdit, @File-Info, @Information
# Test: OSX 10.9.5
# Vers: 0.04 { Build 011 }
-------------------------------------------------------------------------------------------

try


set _sep to "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"


tell application "Finder"
set fSel to selection as alias list
if fSel ≠ {} then
set fileAlias to first item of fSel
set fileURL to URL of fileAlias
else
error "No files are selected in the Finder!"
end if
end tell


set itemInfo to info for fileAlias
set dCre to strftime (creation date of itemInfo) into "%Y/%m/%d %H:%M:%S"
set dMod to strftime (modification date of itemInfo) into "%Y/%m/%d %H:%M:%S"
set displayName to "File-Info » " & (name of itemInfo)
set hfsPath to ("Path HFS : " & fileAlias as text) & linefeed
set relativeHFSPath to "Path HFS Relative : " & makeRelativeAlias(fileAlias) & linefeed
set posixPath to "Path Posix : " & POSIX path of fileAlias & linefeed
set tildePath to change (POSIX path of (path to home folder)) into "~/" in posixPath


if tildePath ≠ posixPath then
set tildePath to change "(Posix)" into "\\1-Home" in tildePath with regexp
else
set tildePath to change "(Posix)" into "\\1-Home" in tildePath with regexp
set tildePath to change "(:\\t).+" into "\\1None" in tildePath with regexp
end if


try
itemInfo / 0
on error e
set e to change "\\A[^{]+?\\{|\\}[^}]+\\Z" into "\\n" in e with regexp without case sensitive
set e to change "\\x{00}" into "" in e with regexp without case sensitive
set e to change "\\r" into "\\n" in e with regexp without case sensitive
set e to change ", ([^,]+[[:alpha:]]:[[:alnum:]\"{])" into "\\n\\1" in e with regexp without case sensitive
set e to change "^([^:]+)(:)" into "\\1\\t\\2\\t" in e with regexp without case sensitive
set e to change "\"" into "" in e with regexp without case sensitive
set e to change "(\\A\\s+name.+\\n)" into "\\1" & hfsPath & relativeHFSPath & posixPath & tildePath in e with regexp without case sensitive


# Path Posix-Home --> Add File-URL after this line item.
set e to change "^(Path Posix-Home.+)" into "\\1\\n" & "Path File-URL : " & fileURL in e with regexp without case sensitive


# Make Table
set e to do shell script "column -t -s' ' <<< " & quoted form of e without altering line endings


# Keep the list neat for Script Debugger & Applescript Editor
set e to linefeed & e


set e to change "^(\\w)" into "\\u\\1" in e with regexp without case sensitive
set e to change "( )(\\w)(\\w+  )" into "\\1\\u\\2\\3" in e with regexp without case sensitive
set e to change "(?-i)alias " into "" in e with regexp without case sensitive
set e to change "(\\.app):(\"\\))?$" into "\\1\\2" in e with regexp without case sensitive
set e to change "(^Creation Date.+)" into "\\1" & " » " & dCre in e with regexp without case sensitive
set e to change "(^Modification Date.+)" into "\\1" & " » " & dMod in e with regexp without case sensitive
set dateSpacer to {matchLen of item 1, matchLen of item 2} of (find text "^.+»" in e with regexp and all occurrences without case sensitive)
set dateSpacer to (maximum of (statlist dateSpacer)) as integer
set e to change "»" into "          »" in e with regexp without case sensitive
set e to change "^(.{" & dateSpacer & "}) +»" into "\\1» " in e with regexp without case sensitive


end try


set e to change "^\\s+" into "" in e with regexp without case sensitive # For neater display in BBEdit
set e to _sep & linefeed & e & _sep & linefeed & (do shell script "mdls " & qf(POSIX path of fileAlias)) & linefeed & _sep & linefeed


tell application "BBEdit"
activate
make new document with properties {name:displayName, bounds:{0, 44, 1920, 1196}, text:e}
tell front text window to select insertion point before its text
end tell


on error e number n
stdErr(e, n, true, true) of me
end try

------------------------------------------------------------------------------------------------
--» HANLDERS
-------------------------------------------------------------------------------------------

on makeRelativeAlias(_item)
set pathToSpec to {application support, applications folder, desktop, desktop pictures folder, documents folder, downloads folder, favorites folder, Folder Action scripts, fonts, help, home folder, internet plugins, keychain folder, library folder, modem scripts, movies folder, music folder, pictures folder, preferences, printer descriptions, public folder, scripting additions folder, scripts folder, shared documents, shared libraries, sites folder, startup disk, startup items, system folder, system preferences, temporary items, trash, users folder, utilities folder, workflows folder}
set expandedPathTo to {}


repeat with i in pathToSpec
set end of expandedPathTo to path to (get contents of i) from user domain
end repeat


set AppleScript's text item delimiters to linefeed
set expandedPathTo to paragraphs of (expandedPathTo as text)
set AppleScript's text item delimiters to ":"
set _item to _item as text
set _len to (length of (text items of _item))
repeat with i from _len to 1 by -1
set _path to ((text items 1 thru i of _item) as text) & ":"
if _path is in expandedPathTo then
repeat with idx from 1 to (length of expandedPathTo)
if (item idx of expandedPathTo) = _path then
set refFldr to "path to " & (item idx of pathToSpec) as text
set diskLocalRef to ("alias " & ("(" & "(" & refFldr & " as text) & ") & "\"" & (text items (i + 1) thru -1 of _item) as text) & "\")"
try
run script diskLocalRef
on error
set refFldr to refFldr & " from user domain"
set diskLocalRef to ("alias " & ("(" & "(" & refFldr & " as text) & ") & "\"" & (text items (i + 1) thru -1 of _item) as text) & "\")"
try
run script diskLocalRef
on error e
error e
end try
end try


return diskLocalRef


end if
end repeat
end if
end repeat
end makeRelativeAlias

-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on stdErr(e, n, beepFlag, ddFlag)
set e to e & return & return & "Num: " & n
if beepFlag = true then
beep
end if
if ddFlag = true then
tell me
set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
end tell
if button returned of dDlg = "Copy" then set the clipboard to e
else
return e
end if
end stdErr
-------------------------------------------------------------------------------------------
on qf(_text)
return (quoted form of _text)
end qf
-------------------------------------------------------------------------------------------

 _______________________________________________
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

  • Prev by Date: Re: New Office for Mac Beta and Applescript
  • Next by Date: Re: Can I add text to the Administrator setting of a shell script?
  • Previous by thread: Re: Can I add text to the Administrator setting of a shell script?
  • Next by thread: bizarre acrobat script problem
  • Index(es):
    • Date
    • Thread