• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Generating applescript files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Generating applescript files


  • Subject: Re: Generating applescript files
  • From: Andy Wylie <email@hidden>
  • Date: Thu, 16 May 2002 20:04:55 +1200

on 16/5/02 1:40 PM +1200: Alex Robinson wrote:

> Is it possible to generate a file that can then be run as a compiled
> applescript?
>
> I tried the following:
>
> set scriptName to "blech"
>
> tell application "Finder"
> set theScript to "-- text of script goes here"
> set theFile to ("HardDisk:Users:sgp:Desktop:" & scriptName)
> set the openFile to open for access file theFile with write permission
> set eof of the openFile to 0
> write theScript to the openFile starting at eof
> close access the openFile
> set theFile to file theFile
> set creator type of theFile to "ToyS"
> set file type of theFile to "osas"
> end tell
>
> But when trying to open the file, I get:
>
> "Could not read the file because of a scripting-system (OSA) error"
>
> Which I suppose is fair enough seeing that I've basically made a
> straightforward text file and then just changed the types.
>
> So what do I actually need to do or is this kind of thing only possible if
> using a scriptable editor like Script Debugger?
> _______________________________________________

I use this text window button script in Smile...

property theFold : missing value
property defBla : "Choose a folder to save to"
property defFold : path to "desk"

on mouseUp(theButton)
if (get exists alias (theFold as string) of application "Finder") =
false then
set theFold to gPath(theFold)
end if

if modifiers = {option down} then

try
tell application "Finder"
open theFold
activate
end tell
on error m number n
error {n, m}
end try

else if modifiers = {caps lock down} then

set theFold to gPath(theFold)

else

set theWind to container of theButton
set txt to selection of theWind as string

if txt is "" then
set {w, cutFlag} to {text of theWind as styled text, 0}
set pX to paragraph index of word 1 of text of theWind
else
set {w, cutFlag} to {selection of theWind as styled text, 1}
set pX to paragraph index of word 1 of selection of theWind
end if

set nameStr to text 1 thru length of (theWind's paragraph pX as
text)
set nameStr to change "--" into "" in nameStr
set nameStr to change ":" into "" in nameStr

if length of nameStr is greater than 30 then
set nameStr to (text 1 thru 30 of nameStr)
else
set nameStr to (text 1 thru -1 of nameStr)
end if

if cutFlag = 1 then
set selection of theWind to ""
else
set text of theWind to ""
end if

doMake(w, theFold, nameStr)

end if
end mouseUp

on doMake(w, theFold, nameStr)
if modifiers is {shift down} then

tell current application
set x to make new script window with properties {name:nameStr}
set contents of window nameStr to w
save x in ((path to "desk") & nameStr as string)
end tell

else

tell current application
set x to make new text window with properties {name:nameStr}
set contents of window nameStr to w
save x in (theFold & nameStr as string)
end tell

end if
end doMake

on gPath(theFold)
try
set the clipboard to StdDate(current date)
set theFold to navchoose folder with prompt "the current folder is:
" & ,
theFold starting at (path to "desk")
return theFold
on error m number n
error {m, n}
end try
end gPath

on helpString(theButton)
"saves the selection of the window or whole contents if selection is
\"\" and opens it's window frontmost. The first line of text (after '--'
comment if it exists) is the title.
Modifiers...
Shift = script (text is default)
Caps Lock = choose save folder
Option = open save folder"
end helpString


_____________________________ Andy
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Generating applescript files (From: Alex Robinson <email@hidden>)

  • Prev by Date: running an AppleScript from terminal command line
  • Next by Date: Re: running an AppleScript from terminal command line
  • Previous by thread: Generating applescript files
  • Next by thread: Re: Generating applescript files
  • Index(es):
    • Date
    • Thread