Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clemsam/5ab1094da7e5b5725fad to your computer and use it in GitHub Desktop.
Save clemsam/5ab1094da7e5b5725fad to your computer and use it in GitHub Desktop.
APPLE Safari: wider downloads window w. full file names, using AppleScript, "System Events" and folder action scripts
My workaround solution for a wider "downloads window" (naturally hiding vital information in longer
file names, e.g. *.otrkey files) uses applescript to directly ACCESS "Downloads.plist", and places
a link in Safari's favorites bar:
First you save these scripts into "~/Library/Scripts/Folder action scripts/" folder, next you attach them
(context menu: configure folder actions) to a new "Folder1" somewhere deep down on your Mac.
To activate them, you will address a (meaningless) dummy "Folder2" inside "Folder1" thru this bookmark:
file:///Path/to/first/Folder1/Folder2 [place link in your favorites bar!]
Now, what happens:
- The clicked-on toolbar link will open "Folder1" because the called upon "Folder2" is inside.
- Thus BOTH attached scripts are launched, #-1 closing the bookmarked "Folder2" window...
- ... next ordering "System Events" to get all of Safari's "DownloadEntryPath" items.
- These paths are shortened to name plus parent-folder and collected into a "dialog alert".
- (Waiting for "dialog window":) #-2 script immediately on pop-up moves it to the top-right.
Let's get started - these two applescripts are needed to run the show:
on opening folder this_folder
tell application "Finder" to close front window
tell application "System Events"
set the plist_path to "~/Library/Safari/Downloads.plist"
set the plist_file to property list file plist_path
set downloadItems to property list items of property list item ¬
"DownloadHistory" of plist_file
set DL_display to ""
set AppleScript's text item delimiters to {"/"}
repeat with i from 1 to number of items in downloadItems
set DL_item to (get text items -2 thru -1 of ((value of ¬
property list item "DownloadEntryPath" of property ¬
list item i of property list item 1 of plist_file) as string))
set DL_display to DL_display & return & "[" & ¬
text item 1 of DL_item & ":]" & return & text item 2 of ¬
DL_item & return
end repeat
tell application "Finder" to display dialog DL_display as string ¬
buttons {"Close"} default button 1
end tell
end opening folder
Here's the 2nd "folder action script" to "Folder1" that moves your "dialog" to the right/top:
on opening folder this_folder
tell application "Finder"
set screenRgt to bounds of the window of desktop
set rightEdge to (item 3 of screenRgt) - 425
end tell
tell application "System Events" to tell process "Finder"
repeat while not (exists window "Recent downloads")
end repeat -- wait for "dialog window" !
set position of window "Recent downloads" to {rightEdge, 61}
end tell
end opening folder
I was really astonished how "tell application" or "tell process" or even "tell application process" each
triggered quite different behaviours in the scripts. I admit to not yet quite understanding the "whys" ...
but I'm slowly getting a "feeling" for applescript ...
(Next I'll look into AppleScriptObjC -Shane Stanley's- and what else can be tweaked with that.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment