Last active
July 30, 2017 07:07
-
-
Save choc-design/dbcfaffa2f67c25150057769eda7d639 to your computer and use it in GitHub Desktop.
webloc muncher with display dialog for debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
property extension_to_rename : {"webloc"} | |
property extension_to_exctract : {"xml"} | |
on open theDroppedItems | |
repeat with a from 1 to count of theDroppedItems | |
set theCurrentItem to item a of theDroppedItems | |
tell application "Finder" | |
set isFolder to folder (theCurrentItem as string) exists | |
end tell | |
-- Process a dropped folder | |
if isFolder = true then | |
renameToXML(theCurrentItem) | |
processFolder(theCurrentItem) | |
end if | |
end repeat | |
end open | |
on processFolder(theFolder) | |
-- NOTE: The variable theFolder is a folder reference in AppleScript alias format | |
-- Retrieve a list of any visible items in the folder | |
set theFolderItems to list folder theFolder without invisibles | |
set allURLs to "" | |
set linebreak to linefeed & linefeed | |
-- Loop through the visible folder items | |
repeat with a from 1 to count of theFolderItems | |
set theFolderItem to ((theFolder as string) & (item a of theFolderItems as string)) as string | |
tell application "Finder" to set fileExtension to name extension of (theFolderItem as alias) | |
if (fileExtension is in the extension_to_exctract) then | |
tell application "System Events" | |
tell property list file theFolderItem | |
set extractedURL to value of property list item "URL" | |
-- display dialog extractedURL as string | |
set allURLs to (allURLs & (extractedURL as string) & linebreak) | |
end tell | |
end tell | |
end if | |
end repeat | |
-- Add additional folder processing code here | |
set {year:y, month:m, day:d} to (current date) | |
set today to (y * 10000 + m * 100 + d) as string | |
-- display dialog theDate as string | |
set folderPath to POSIX path of (theFolder as string) | |
-- display dialog folderPath as string | |
if contents of allURLs is not "" then | |
do shell script "cd " & quoted form of (folderPath as string) & "; echo " & quoted form of (allURLs as string) & " > " & today & "_extracted_urls.txt" | |
end if | |
end processFolder | |
on renameToXML(theFolder) | |
tell application "Finder" to repeat with theFile in (get document files of theFolder) | |
set this_extension to the name extension of theFile | |
-- display dialog this_extension as string | |
if (this_extension is in the extension_to_rename) then | |
set fileNameWithExtension to name of theFile | |
set fileName to text 1 thru ((offset of "." in fileNameWithExtension) - 1) of fileNameWithExtension | |
-- display dialog fileName as string | |
set name of theFile to fileName & ".xml" | |
end if | |
end repeat | |
end renameToXML | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment