My first script will do http://macscripter.net/books/ even throw it doesn’t exist
comes up with http://www.macscripter.net/
work on http://subdomain.book.macscripter.net/books/
also comes up with http://www.macscripter.net/
also work with also http://www.comment.com/
where there two .com thats why search for .com/ com with the slash
doesn’t work on
http://www.apple.ru/
simple because .ru is not in SuffixOptions list
mark I learn something off you, a -1 with thru go to the end, not logical but works, my way using length eg
set Thehost to "[url=http://www.macscripter.net]www.macscripter.net[/url]" as string
set FirstDomain to characters 5 thru -1 of Thehost as string
set SecondDomain to characters 5 thru (length of Thehost) of Thehost as string
Here an example of use
This script save the webpage text to text file named host and timestamp
Achrive into host folder in a a chest in extacts, nice UNIX method making folders
Puts the URL in the comments for later getting
tell application "Safari"
activate
set TheText to text of document 1
set TheURL to URL of document 1
set TheHost to (do JavaScript "location.host" in document 1)
end tell
set TimeStamp to do shell script "date -n +%Y-%m-%d-%H-%M-%S"
set thepath to ((path to desktop) as string) & "chest:extracts:" & TheHost & ":"
set TheName to TheHost & "-" & TimeStamp & ".txt"
do shell script "mkdir -p " & (POSIX path of thepath)
set theFile to thepath & TheName
try
set fileref to (open for access theFile with write permission)
set eof fileref to 0
write TheText to fileref as string
close access fileref
on error number x
display dialog "Error " & x & ": did not write"
close access fileref
end try
tell application "Finder"
set comment of file theFile to TheURL
end tell
better yet use my script like this
property TheURL : "http://www.macscripter.net/"
property SuffixOptions : {".com", ".net", ".org", ".info", ".us", ".biz", ".tv", ".mobi", ".cc", ".ws", ".bz", ".tc", ".vg", ".ms", ".gs", ".name", ".co.uk", ".de", ".be", ".eu", ".at", ".com.mx", "org.uk", ".me.uk", ".co.nz", ".net.nz", ".org.nz", ".cn", ".tw"}
tell application "Safari"
activate
set TheText to text of document 1
set TheURL to URL of document 1
end tell
set TheHost to FindDomainName(TheURL)
set TimeStamp to do shell script "date -n +%Y-%m-%d-%H-%M-%S"
set thepath to ((path to desktop) as string) & "chest:extracts:" & TheHost & ":"
set TheName to TheHost & "-" & TimeStamp & ".txt"
do shell script "mkdir -p " & (POSIX path of thepath)
set theFile to thepath & TheName
try
set fileref to (open for access theFile with write permission)
set eof fileref to 0
write TheText to fileref as string
close access fileref
on error number x
display dialog "Error " & x & ": did not write"
close access fileref
end try
tell application "Finder"
set comment of file theFile to TheURL
end tell
on FindDomainName(TheURL)
set TheSuffix to ""
repeat with CurrentSuffix in SuffixOptions
if TheURL contains (CurrentSuffix & "/") then
set TheSuffix to CurrentSuffix
exit repeat
end if
end repeat
if TheSuffix = "" then
return "Misc"
else
set SuffixOffset to offset of (CurrentSuffix & "/") in TheURL
set JustDomain to (characters 1 thru (SuffixOffset - 1) of TheURL) as string
set PointOffSet to 0
repeat with NegOffSet from (length of JustDomain) to 1 by -1
if character NegOffSet of JustDomain is "." or character NegOffSet of JustDomain is "/" then
set PointOffSet to NegOffSet
exit repeat
end if
end repeat
set JustDomain to (characters (PointOffSet + 1) thru (length of JustDomain) of JustDomain as string) & CurrentSuffix
return JustDomain
end if
end FindDomainName
needs a bit of work, blanks results should not try and write, no documents
simple change
set TheText to source of document 1
set thepath to ((path to desktop) as string) & “chest:source:” & TheHost & “:”
and it save the source as txt