• 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
Default_Folder_Rules!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Default_Folder_Rules!


  • Subject: Default_Folder_Rules!
  • From: Christopher Stone <email@hidden>
  • Date: Tue, 06 Mar 2012 14:44:14 -0600

Hey Folks,

For you Default Folder users out there.

I save quite a lot of webarchive files - generally preferring them to printing-to-pdf for various reasons.

Since a lot of these are from the same sites and similar subjects I wanted to simplify the filing process.

Hence the appended script.

My first effort used the Satimage.osax for all the lookups and parsing, but I wanted to provide Jon Gotow (DF's developer) with a go anywhere vanilla version.

Presently I'm going to rewrite the vanilla version to use tools from the shell, so I thought I'd post this one to the list for anyone whose interested.  (I'll post the new one later.)

Simply the script does this in Safari:

Uses Keyboard Maestro to intercept the save keyboard shortcut (Cmd-S).

Looks for the domain of the front document.

Looks to see if there is an associated folder for that domain and if so uses Default Folder to switch the Save-Dialog-Location to that folder.

--
Best Regards,
Chris


------------------------------------------------------------------------------------------------
#       Author: Christopher Stone
#      Created: 2011-01-15 : 10:16
#     Modified: 2012-02-01 : 12:18
#  Application: Safari & Default Folder
#      Purpose: Save to Specified Folders Using Rules
# Dependencies: Default Folder & keystroke-driven Applescript-runner utility like Keyboard Maestro.
------------------------------------------------------------------------------------------------
# PROPERTIES
------------------------------------------------------------------------------------------------
property webArchiveFolder : ("" & (path to documents folder) & "Web Archives:")
property lookupTable : "
------------------------------------------------------------------------------------------------
|apple.com|                                                   ;Apple;
|support.apple.com|                                           ;Apple;
|mactech.com|                                                 ;MacTech.com;
|reviews.cnet.com|                                            ;CNET;
|hints.macworld.com|                                          ;Mac OS X Hints;
|lists.apple.com|macscripter.net|                             ;Applescript;
|trac.macports.org|                                           ;MacPorts;
|macworld.com|                                                ;Macworld;
|nytimes.com|                                                 ;New York Times (The);
|regular-expressions.info|                                    ;Regular _expression_ Reference;
|techrepublic.com|                                            ;TechRepublic;
|techsupportalert.com|                                        ;Gizmo;
|thegeekstuff.com|                                            ;Geek Stuff (The);
|tidbits.com|                                                 ;TidBITS;
|zdnet.com|                                                   ;zdnet.com;
------------------------------------------------------------------------------------------------
"
#### NOT YET IN USE ####
property keywordLookupTable : "
------------------------------------------------------------------------------------------------
|_javascript_|                                                  ;_javascript_;
|perl|                                                        ;Perl;
|regular _expression_|                                          ;Regular Expressions;
|ruby|                                                        ;Ruby;
------------------------------------------------------------------------------------------------
"
------------------------------------------------------------------------------------------------
# HANDLERS
------------------------------------------------------------------------------------------------
on FIND_REPLACE(findText, replaceText, srcText)
set oldTIDS to AppleScript's text item delimiters
set AppleScript's text item delimiters to findText
set srcText to text items of srcText
set AppleScript's text item delimiters to replaceText
set srcText to srcText as text
end FIND_REPLACE
------------------------------------------------------------------------------------------------
on DO_LOOKUP(lookupText)
try
set destinationFolder to null
set AppleScript's text item delimiters to "."
set lookupTextSplit to text items of lookupText
set lookupTextLength to length of lookupTextSplit


repeat with i from 1 to (lookupTextLength - 1)
set parsedLookupText to items i thru -1 of lookupTextSplit
set parsedLookupText to parsedLookupText as text
set parsedLookupText to "|" & parsedLookupText & "|"


if parsedLookupText is in lookupTable then
set AppleScript's text item delimiters to {parsedLookupText}
set lookupResult to text item 2 of lookupTable
set AppleScript's text item delimiters to {";"}
set lookupResult to text item 2 of lookupResult
set destinationFolder to alias (webArchiveFolder & lookupResult)
end if
end repeat


return destinationFolder


on error
error "Failure in DO_LOOKUP() Handler"
end try
end DO_LOOKUP
------------------------------------------------------------------------------------------------
on GET_SAFARI_URL()
tell application "Safari"
try
if front document exists then
return URL of front document
end if
on error
error "Failure in GET_SAFARI_URL() Handler."
end try
end tell
end GET_SAFARI_URL
------------------------------------------------------------------------------------------------
on PARSE_URL_FOR_LOOKUP(pageURL)
set AppleScript's text item delimiters to "/"
set parsedURL to text item 3 of pageURL
set AppleScript's text item delimiters to "www."
set parsedURL to last text item of parsedURL
set AppleScript's text item delimiters to {""}
return parsedURL
end PARSE_URL_FOR_LOOKUP
------------------------------------------------------------------------------------------------
on SPLIT_TEXT(sourceText, deLimiter)
try
set oldTIDS to AppleScript's text item delimiters
set AppleScript's text item delimiters to deLimiter
set newList to text items of sourceText
set AppleScript's text item delimiters to oldTIDS
return newList
on error
error "Failure in SPLIT_TEXT() Handler of General Library."
end try
end SPLIT_TEXT
------------------------------------------------------------------------------------------------
on SHIFT_DIALOG_DESTINATION(destinationFolder)
tell application "Safari"
if front document exists then
delay 0.1
tell application "Default Folder X Helper"
if IsDialogOpen then
if (GetCurrentFolder) ≠ destinationFolder then
SwitchToFolder destinationFolder


# Feature Reminder:
# SetSaveName "Some Custom Name"


end if
else
error "Failure in SHIFT_DIALOG_DESTINATION() Handler."
end if
end tell
else
error "Safari has no documents open."
end if
end tell
end SHIFT_DIALOG_DESTINATION
------------------------------------------------------------------------------------------------
# MAIN
------------------------------------------------------------------------------------------------
try
set pageURL to GET_SAFARI_URL()
set parsedURL to PARSE_URL_FOR_LOOKUP(pageURL)
set destinationFolder to DO_LOOKUP(parsedURL)
if destinationFolder ≠ null then
SHIFT_DIALOG_DESTINATION(destinationFolder)
end if
on error errMsg number errNum
beep
tell me to display dialog "Error: " & errMsg & return & "Error Number: " & errNum
end try

 _______________________________________________
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: Default_Folder_Rules!
      • From: email@hidden
  • Prev by Date: Re: Scripting a watermark with Graphic Converter
  • Next by Date: Re: InDesign CS5 Next style is not applied
  • Previous by thread: InDesign CS5 Next style is not applied
  • Next by thread: Re: Default_Folder_Rules!
  • Index(es):
    • Date
    • Thread