|
|
#1 |
|
Prospect
Join Date: Jul 2012
Posts: 1
|
osascript untitled applescript
what would be the way to osascript a untitled applscript??
I'm expecting something: -e `"some code to refer to the untitled in the active scripteditor"' or even better: a pathway to the untitled script ... would like to do this without saving the script, without typing too much in the terminal shell: tell application "Finder" choose file set file1 to result open file1 say "file opened" using "victoria" end tell ...as a novice to this, I enjoy being entertained by applications communicating in any way. appreciate and respect the time and effort by those dedicated to "the codes" and willing to help "novices like me" to get some relaxation from playing with a computer. best regards, openbox |
|
|
|
|
|
#2 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,941
|
Not sure, but I think you are asking how to run an AppleScript that you have typed into Script Editor (but have not saved).
This is unusual - why not save it? But you can run an AppleScript (saved or not) by using the "Run" button of Script Editor. Why are you wanting to use Terminal and 'osascript' to do this? If you insist on using Terminal, then I guess you could write an AppleScript (call it "foo") that would tell Script Editor to run the current script and then run the "foo" ApplEscript via 'osascript' in Terminal. Or maybe you would like to try using my "AppleScript Shell" that allows you to type AppleScript commands into a Terminal session (running that shell): http://hayne.net/MacDev/Ash/ See also this Unix FAQ
__________________
hayne.net/macosx.html |
|
|
|
|
|
#3 |
|
Major Leaguer
Join Date: Apr 2005
Posts: 477
|
I have already written a script for this. It turns the selected text in the frontmost applescript editor window into an osascript command for the Terminal. You can have it! Just create this script and it can be run from the applescript menu or as an application.
Code:
-- instructions for user
display dialog "This will turn the selected code in Applescript Editor into an osascript suitable for the Terminal. The Terminal will open and the osascript is put there." buttons {"Quit", "Go"} default button 2 with icon note
set br to button returned of result
if br is "Quit" then return
-- get the selected code from the front Applescript Editor document
tell application "AppleScript Editor"
activate
delay 0.3
tell document 1
set selectedText to contents of selection
end tell
end tell
-- make a list with each line of the code
set theParas to paragraphs of selectedText
-- first we remove the leading spaces, tabs, and empty lines... and add single quotes around each list item
set singlequoteList to {}
repeat with i from 1 to count of theParas
set thisPara to item i of theParas
if thisPara is not "" then
set thisPara to removeLeadingSpaces(thisPara)
set thisPara to removeLeadingTabs(thisPara)
set end of singlequoteList to "'" & thisPara & "'"
end if
end repeat
-- make it a long string separated by -e
set {tids, text item delimiters} to {text item delimiters, " -e "}
set stringCmd to singlequoteList as text
-- replace \ with \\
set stringCmd to findReplace(stringCmd, "\\", "\\\\")
-- make the entire do shell script cmd
set text item delimiters to tids
set stringCmd to "/usr/bin/osascript -e " & stringCmd
tell application "Terminal" to activate
delay 0.3
tell application "System Events" to keystroke stringCmd
(*================= SUBROUTINES ===============*)
on findReplace(theString, search_string, replacement_string)
if theString contains search_string then
set AppleScript's text item delimiters to search_string
set text_item_list to text items of theString
set AppleScript's text item delimiters to replacement_string
set theString to text_item_list as text
set AppleScript's text item delimiters to ""
end if
return theString
end findReplace
on removeLeadingSpaces(theString)
repeat while theString begins with space
set theString to text 2 thru -1 of theString
end repeat
return theString
end removeLeadingSpaces
on removeLeadingTabs(theString)
repeat while theString begins with tab
set theString to text 2 thru -1 of theString
end repeat
return theString
end removeLeadingTabs
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|