AppleScript get filename from URL and apply Decode URL 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 " &amp; 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:

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


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

%5BEBOOKS%5DEbook%20Title%20-%20Ebook%20Author%20Name.pdf


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"