簡單講,就是用AppleScript+Pashua,做一個Terminal.app連到BBS的前端介面,所以如果要正常連到BBS,您也必須把Terminal.app先設定好。
首先,先去抓 Pashua,這是一個簡單的GUI產生器。把 Pashua 複製到硬碟當中的某個地方。 下載網址是 http://q41.de/downloads/pashua_en/
然後打開「應用程式」->「AppleScript」-> 「工序指令編寫程式」
填入以下程式碼,然後存成「應用程式」,放在與Pashua同一個目錄下,這段程式碼也是用Pashua的範例改的。:p
代碼: 選擇全部
(*
ATTENTION:
1. If you run this script from Script Editor and had a previous version of
Pashua installed, probably this script will use the older version instead of the
newer one. To avoid this misbehaviour, either run the script by doubleclicking it,
or remove any older versions. (Instead of removing, you can also rename it or put
in a non-standard location.)
2. If you run this script from Script Editor and never used Pashua before, you
will get an error message saying that Pashua could not be found. In this case,
either run this script by doubleclicking its icon, or copy the Pashua application
to /Applications or ~/Applications.
*)
-- Create a configuration string which will be used to
-- tell Pashua what types of GUI elements you need and
-- which default values (if any) should be used
set config to "
# Lines starting with a hash character are
# comments, empty lines are ignored
# Set transparency: 0 is transparent, 1 is opaque
transparency=0.95
# Set window title
windowtitle=打BBS
# Define some introductory text
txt_type=text
txt_text=BBS快速連接器
# A separator line
-
# Define a password field
host_label=請輸入您所要連線的BBS的位置
host_type=combobox
host_width=390
host_option=ptt.cc
host_option=ptt2.cc
host_default=ptt.cc
# Add a cancel button - if you like, you can set the
# button label by uncommenting the second line below
cancel_type=cancelbutton
#cancel_label=If you click here, no values will be returned
# Define a default button - if you like, you can set the
# button label by uncommenting the second line below
default_type=defaultbutton
#default_label=Click here to return the values
"
-- Call Pashua and save the resulting record in pashuaResult
set pashuaResult to pashua_run(config)
if cancel of pashuaResult is not "1" then
tell application "Terminal"
do script "telnet -8 " & host of pashuaResult & ";exit"
end tell
end if
-- Glue code for interfacing from AppleScript to Pashua. Written by
-- Carsten Bl?m <bluem@q41.de>, 10/2003-12/2003, with an improvement
-- contributed by Eddy Roosnek. You can use or modify this handler
-- any way you like in your own scripts.
on pashua_run(config)
-- Create path for temporary file
set AppleScript's text item delimiters to ""
set tmpfile to ((path to temporary items folder as string) & "Pashua_" & (characters 3 thru end of ((random number) as string)) as string)
-- Write temporary file and fill it with the configuration string
set fhandle to open for access tmpfile with write permission
write config to fhandle
close access fhandle
-- Get temporary file's POSIX path
set posixtmpfile to POSIX path of tmpfile
set diskPath to (path to startup disk as string)
tell application "Finder" to set userPath to path to "cusr" as string
set myself to (path to me as string)
tell application "Finder" to set myParentPath to (container of alias myself as string)
tell application "Finder" to set myPath to (myself as string)
-- Try to find Pashua application
tell application "Finder"
-- Try to find it in this script application bundle
if item (myPath & "Contents:MacOS:Pashua") exists then
set pashua to myPath
-- Try to find it in this script's parent's path
else if item (myParentPath & "Pashua.app") exists then
set pashua to (myParentPath & "Pashua.app:")
-- Try to find it in global application folder
else if item (diskPath & "Applications:Pashua.app") exists then
set pashua to (diskPath & "Applications:Pashua.app:")
-- Try to find it in user's application folder
else if item (userPath & "Applications:Pashua.app") exists then
set pashua to (userPath & "Applications:Pashua.app:")
else
display dialog "I can't find the Pashua application." & return & "It looks like Pashua is neither in one of the standard locations nor in the folder this AppleScript is in." buttons {"OK"} default button 1 with icon stop
return -1
end if
end tell
-- Append binary position inside app bundle to "regular" path
-- and convert path from HFS to POSIX representation
set pashuabinary to (POSIX path of pashua) & "Contents/MacOS/Pashua"
-- Execute pashua and get the string returned
set pashuaResult to do shell script ("'" & pashuabinary & "' '" & posixtmpfile & "'")
-- Delete the temporary file
tell application "Finder" to delete tmpfile
-- Check whether the dialog was submitted at all.
-- If this is not the case, return an empty list
if pashuaResult = "" then
return {}
end if
-- Parse the result
set AppleScript's text item delimiters to return
set resultLines to text items of pashuaResult
set AppleScript's text item delimiters to ""
set recordComponents to {}
repeat with currentLine in resultLines
set eqpos to offset of "=" in currentLine
if eqpos is not 0 then
set varKey to (characters 1 thru (eqpos - 1) of currentLine as string)
try
set varValue to (characters (eqpos + 1) thru end of currentLine as string)
-- Quote any quotation marks in varValue with a backslash.
-- The proper way to do this would be a handler, but as
-- all code for interfacing to Pashua should be as compact
-- as possible, we rather do it inline
set AppleScript's text item delimiters to "\""
set textItems to every text item of varValue
set AppleScript's text item delimiters to "\\\""
set varValue to textItems as string
set AppleScript's text item delimiters to ""
on error
set varValue to ""
end try
copy (varKey & ":\"" & varValue & "\"") to end of recordComponents
end if
end repeat
-- Return the record we read from the tmpfile
set AppleScript's text item delimiters to ", "
return (run script "return {" & (recordComponents as string) & "}")
end pashua_run