I have a need to change a site over from a static html site to WordPress. I haven’t been able to find a way to script WordPress since it isn’t listed as a dictionary entry.
So, what I want to do instead is eliminate all the line breaks using text wrangler. Unfortunately there are over 600 files and I wanted to automate this if possible. I have found that in the dictionary there is a “remove line breaks” command.
set theFolder to ("/users/abc/sites/help_file")
tell application "Finder" to set theFiles to every file of theFolder
set allContents to ""
repeat with aFile in theFiles
set aFile to aFile as string
set allContents to allContents & (read file aFile) & return
tell application "TextWrangler"
remove line breaks
end tell
end repeat
When I run the script I get the error “Can’t get every file of "/users/abc/sites/help_file".” number -1728 from every file of “/users/abc/sites/help_file”
There are only 10 files in the abc folder so please advise what I need to change. All of the files and folders combined will be over 600.
Or, if my approach can be improved please tell me. I am new to scripting and found the repeat script on the forum.
Finder doesn’t know posix paths (“users/abc/sites/help_file”). To change a posix path to one Finder can understand:
Ex. 1
set posix_path to "/Users/kelhome/sites/help_file"
set mac_ref to POSIX file (posix_path)
From there there’s more.
Anyway, as ccstone wrote, using another app might make it slow. You might want to use vanilla AppleScript (Standard Additions) read/write commands. It’s not to slow if you read the whole text, modify, and rewrite the whole file.
A fast way to get the posix path of a selection, when you just want to operate on one item:
tell application "Finder"
if selection = {} then
beep
return
end if
set n to (count selection as list)
if n > 1 then
beep
return
else
set a to POSIX path of (selection as alias)
end if
end tell
I use aliases pretty much everywhere (except in the shell of course).
tell application "SystemUIServer" to activate -- Work around L/ML Finder-selection bug.
tell application "Finder"
activate
set _sel to selection as alias list
if _sel = {} then
error "No items were selected!"
else
repeat with i in _sel
set contents of i to "alias \"" & contents of i & "\""
end repeat
set AppleScript's text item delimiters to linefeed
set _sel to _sel as text
end if
end tell
set the clipboard to _sel
I use FastScripts rather than the SystemUIServer on my system, since I run nearly all my Applescripts with it.