I've got the following AppleScript that displays a notification once a download has been added:

set yourpath to (the clipboard) as POSIX file
set a to do shell script "basename " & quoted form of POSIX path of yourpath
display notification a with title "Added Download"

It works pretty well, except when the url being downloaded has a filename with html entities. Here's an example of a URL:


So with my AppleScript I get the following inside the notification:


I'm trying to get:

[EBOOKS]Ebook Title - Ebook Author Name.pdf

You can use Cocoa’s NSURL class via some AppleScriptObjC:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set test to "https://dskjflkosdjfksdajf903094.example.com/g/f/OWZehaoqssVuXRuxqEivP_9dsa89dosidlzkxck_wqezxcd33sda-34sdf34r/%5BEBOOKS%5DEbook%20Title%20-%20Ebook%20Author%20Name.pdf"

set theURL to current application's NSURL's URLWithString:test
set testName to theURL's lastPathComponent as text
display notification testName with title "Added Download"
  • This worked a charm, thanks so much! – StuyvesantBlue Jul 23 at 1:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .