-
-
Save motionbug/4224567 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
on replace_chars(this_text, search_string, replacement_string) | |
set AppleScript's text item delimiters to the search_string | |
set the item_list to every text item of this_text | |
set AppleScript's text item delimiters to the replacement_string | |
set this_text to the item_list as string | |
set AppleScript's text item delimiters to "" | |
return this_text | |
end replace_chars | |
to getScriptEditorDocumentFor(myFileRef) | |
tell application "Finder" to set myAlias to myFileRef as alias | |
tell application "AppleScript Editor" | |
set docs to every document whose path is (POSIX path of myAlias) | |
return item 1 of docs | |
end tell | |
end getScriptEditorDocumentFor | |
tell application "Finder" | |
set sourceFolder to alias "Macintosh HD:Users:ryan:SCRIPTS_AS_SCRIPTS/" | |
set destinationFolder to "/Users/ryan/Desktop/SCRIPTS_AS_APPLESCRIPTS/" | |
set myFileList to every file in sourceFolder | |
repeat with currFile in myFileList | |
set theNameWithExt to name of currFile | |
set theExtension to name extension of currFile | |
tell me to set theName to replace_chars(theNameWithExt, theExtension, "") | |
log currFile | |
tell application "AppleScript Editor" | |
open currFile | |
-- does not seem to return the document opened... | |
-- so figure it out ourselves... | |
-- don't just use window, because that could be the wrong | |
-- window depending on (yay possible fun threading issues!) | |
tell me to set d to getScriptEditorDocumentFor(currFile) | |
--save d as "script" in POSIX file (((destinationFolder & theName as string) & ".scpt") as string) with run only | |
-- ^^^^^^^^^^ the other way around! | |
save d as "text" in POSIX file (((destinationFolder & theName as string) & "applescript") as string) -- with run only | |
-- use a POSIX file because an alias can't point to a nonexistant file | |
-- WD-rpw 02-23-2010 | |
try | |
close window 1 | |
end try | |
-- if you try to close the wrong window here | |
-- (like say this script) we'll get an error | |
-- but the possibility of an error leaving the | |
-- script window open is much less than accidentally | |
-- saving the source of THIS script instead of | |
-- the script you opened. | |
-- WD-rpw 02-23-2010 | |
end tell | |
end repeat | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment