Skip to main content

macos/furl

1#!/usr/bin/env osascript
2# Get the URL of the frontmost Safari window.
4-- An AppleScript function to replace text. Yes, this is really
5-- what it takes.
6--
7-- Example:
8--
9-- replaceText("The cat is red", "red", "green")
10-- /* The cat is green */
11--
12on replaceText(inputText, old, new)
13 set AppleScript's text item delimiters to the old
14 set the itemList to every text item of inputText
15 set AppleScript's text item delimiters to the new
16 set inputText to the itemList as string
17 set AppleScript's text item delimiters to ""
18 return inputText
19end replaceText
21tell application "Safari"
22 set frontmostUrl to URL of document 1
23end tell
25-- Remove the localhost:5959 prefix from my book tracker running
26-- locally -- I never actually want this, just the relative path.
27set frontmostUrl to replaceText(frontmostUrl, "http://localhost:5959", "")
29-- Remove the localhost:5757 prefix from my personal site running
30-- locally -- I never actually want this, just the relative path.
31set frontmostUrl to replaceText(frontmostUrl, "http://localhost:5757", "")
33get frontmostUrl