Showing posts with label Finder. Show all posts
Showing posts with label Finder. Show all posts

2011/05/17

Recreate the folder and file hierarchy in text form compatible with MediaWiki syntax

Let's say we have the following folder and file structure and we would like to pass it as text in a MediaWiki page.

With the AppleScript of this post you can create automatically the necessary text, which is for our example the following:

===DevonThink scripts===
Number of files: 0<pre>/MBSystem/Users/MB/Downloads/DevonThink scripts/</pre>

====Camino====
Number of files: 3<pre>/MBSystem/Users/MB/Downloads/DevonThink scripts/Camino/</pre>
Add PDF document to DEVONthink.scpt<br/>
Add link to DEVONthink.scpt<br/>
Add web document to DEVONthink.scpt<br/>

====DEVONagent====
Number of files: 11<pre>/MBSystem/Users/MB/Downloads/DevonThink scripts/DEVONagent/</pre>
Add PDF document to DEVONthink.scpt<br/>
Add abstracts to DEVONthink Pro.scpt<br/>
Add linked images to DEVONthink's downloads.scpt<br/>
Add linked images to DEVONthink.scpt<br/>
Add links to DEVONthink's downloads.scpt<br/>
Add links to DEVONthink.scpt<br/>
Add page to DEVONthink.scpt<br/>
Add selection to DEVONthink.scpt<br/>
Add tabs to DEVONthink.scpt<br/>
Add text to DEVONthink.scpt<br/>
Add web document to DEVONthink.scpt<br/>

====Firefox====
Number of files: 3<pre>/MBSystem/Users/MB/Downloads/DevonThink scripts/Firefox/</pre>
Add PDF document to DEVONthink.scpt<br/>
Add link to DEVONthink.scpt<br/>
Add web document to DEVONthink.scpt<br/>

====endo====
Number of files: 1<pre>/MBSystem/Users/MB/Downloads/DevonThink scripts/endo/</pre>
Add news to DEVONthink.scpt<br/>
As you can see the folder hierarchy is recreated as a hierarchy of MediaWiki sections. Also the number of files in each folder and its path are added under the name of the corresponding section. If you choose to apply this AppleScript in a folder structure with thousands of files there will no be any problem but it will take a long time to finish.  The result is sent to the clipboard.

The AppleScript code is the following:
set folderContents to show_folder_hierarchy(choose folder, "=") of me

set the clipboard to folderContents
--this subroutine is an expansion of an example from the book Learn AppleScript - The Comprehensive Guide to Scripting on Mac OS X (p. 485-486)
on show_folder_hierarchy(the_folder, the_indent)
    --process this folder
    tell application "Finder"
        set folderContents to get files of the_folder
        set numberOfFiles to count items of folderContents
       
        set folderName to the_folder as alias
        set folderNamePOSIX to get the POSIX path of folderName
        set folderPATH to "<pre>" & folderNamePOSIX & "</pre>"
       
        set fileNames to ""
        repeat with currentFile from 1 to numberOfFiles
            set fileNames to fileNames & name of item currentFile of folderContents & "<br/>" & return
        end repeat
        set the_result to the_indent & "==" & name of the_folder & "==" & the_indent & return & "Number of files: " & numberOfFiles & folderPATH & return & fileNames & return
    end tell
   
    --process each sub-folder in turn
    tell application "Finder"
        repeat with sub_folder_ref in (get every folder of the_folder)
            set the_result to the_result & my show_folder_hierarchy(contents of sub_folder_ref, the_indent & "=")
        end repeat
    end tell
    return the_result
   
end show_folder_hierarchy
2011-05-20 I updated the code which creates the POSIX paths of the folders.  
 

2011/03/24

How to reveal the front Skim PDF document in Finder and in DEVONthink

You can use the following AppleScript to reveal the front Skim PDF document in Finder:

tell application "Skim"
    set FilePath to get the file of front document
    tell application "Finder"
        activate
        reveal FilePath
    end tell
end tell
You can use the following AppleScript to reveal the front Skim PDF document in DEVONthink:

tell application "Skim"
    set the xDEVONthinkLink to (get text for note 4 of document 1) as string
    set customUUID to text 21 thru -8 of xDEVONthinkLink as string
end tell

tell application "DEVONthink Pro"
    activate
    tell database "MySources"
        set myPDF to get record with uuid customUUID
        open tab for record myPDF
        tell application "System Events"
            tell process "DEVONthink Pro" to click menu item "Reveal" of menu 1 of menu bar item "Data" of menu bar 1
        end tell
    end tell
    close document window 1
end tell
In order for the last AppleScript to work properly, you need to have the DEVONthink URL in the fourth Skim note of the first page of the PDF in the following form:

x-devonthink-item://648847AF-4714-4328-916C-6169A6389124?page=0

In my post "How to put DevonThink links in Skim note" I describe how this can be done automatically. 

Moreover you need to adjust appropriately the name of the DEVONthink database  in the line:
    tell database "MySources"