TweetFollow Us on Twitter

Clipboard 2
Volume Number:1
Issue Number:6
Column Tag:BASIC

The Clipboard

By Dave Kelly

One of the features that makes the Macintosh unique from other computers is the use of the clipboard. The clipboard adds flexibility to the Mac user interface. With it you can exchange data from one application to another. Anyone who has worked with MacPaint or MacWrite is familar with the operation of the clipboard. What you cut or copy is saved in the clipboard allowing you to paste it somewhere else! But how do you deal with the clipboard from your own programs? That is the subject we want to explore this month.

Support of the clipboard is another feature of the Macintosh user interface that was left out of MSBASIC version 1.0 but fortunately is easily used in version 2.0. Most of the features that we will use here will only work for version 2.0. There are a few things you should keep in mind when writing programs to use the clipboard.

First, there are three different ways which BASIC can address the clipboard file. Use the OPEN statement with one of the following statements for the filename:

“CLIP:” for transferring data from programs that have tabular data, like Multiplan or Chart.

“CLIP:TEXT” for transfering text to and from word processors and other programs.

“CLIP:PICTURE” for transferring picture data to and from MacPaint or other programs.

Files that are OPENed to this device, using the mode indicated above, will read/write data directly from/to the Clipboard File stored on the system disk.

The sample program ‘Show Clip’ shows how the clipboard could be read within an application and displayed. You have probably seen many applications that give the user the option to “Show Clipboard”. The program will check to see if the clipboard contains picture data or text and will read the data accordingly and display it in the window. This routine is an example to show how to read from the clipboard, but could be used in your own application to produce the “Show Clipboard” option.

When you make use of EDIT FIELDs in your programs you should keep the Edit menu active so that your EDIT FIELD can be fully edited using the cut, copy and paste feature of the Edit menu. This way the clipboard is being used without having to do a whole lot of programing; however the operation is still manual. The user must decide what to select and copy or cut it into the EDIT FIELD. The same is true for inserting text with the paste option.

If the file is opened to “CLIP:” or “CLIP:TEXT”, the data is read sequentially from the clipboard file. There are actually two clipboard areas. One is the clipboard file and the other is a temporary area in memory. That’s why sometimes the disk turns on when you cut or copy something and other times it doesn’t.

To write text to the clipboard:

• Open the clipboard with OPEN “CLIP:” FOR OUTPUT AS #1 or equivalent.

• Use Write #1 or Print #1 to write your variable to the clipboard file.

• CLOSE #1 to close the file.

To read from the clipboard:

• Open the clipboard with OPEN “CLIP:” FOR OUTPUT AS #1 or equivalent.

• Use INPUT #1 to read variables from the clipboard file.

• CLOSE #1 to close the file.

See the program for an example of this.

You should remember to use the proper format when storing data in the clipboard so that other applications may use the data. For example, the text that a word processor uses would contain format control characters imbedded in the text. These kind of characters should only be left in the text stored in the clipboard if you know that the program that will be reading it will use them. Some things might not matter what format they are stored in and the data can be formatted once it has been read into the new application. Most of the applications available will tell you how the data is formatted, so if you know what the data will be used in, there won’t be any problem. Some help on transfering files to and from the clipboard and other applications can be found on page 55 of the BASIC manual.

Copying pictures is just about as easy as text. To transfer something to MacPaint:

• Use the PICTURE ON statement to record the graphics statements.

• Issue all the graphics statements you need to produce the picture. You don’t have to draw it to record it as a picture.

• Use PICTURE OFF to stop recording graphics.

A good example of this is found in the BASIC manual page 205.

• Next open the clipboard file with OPEN “CLIP:PICTURE” FOR OUTPUT AS #1 (or equavalent statement)

• Send the picture to the clipboard with PRINT #1,PICTURE$

• Close the file: CLOSE #1

Next you can either exit BASIC and paste the picture into MacPaint or save the picture in the Scrapbook to use later.

To transfer MacPaint pictures to BASIC:

• Put the MacPaint picture in the Clipboard

• Open the clipboard file with OPEN “CLIP:PICTURE” FOR INPUT AS #1 (or equavalent statement)

• Transfer the picture to a string variable (called image$ in this case): image$=INPUT$(LOF(1),1)

• Close the file: CLOSE #1

• Draw the Picture to the screen exactly the way it was recored: PICTURE,image$

See the program for an example of reading a picture from the clipboard.

To determine if the data in the clipboard is picture or text we can use the BASIC statement LOF. LOF(1) will return the length of the specified file (in this case our file is “CLIP:”. If the result turns out to be zero, it means that either the data is a picture or the clipboard is empty. So next just read whatever picture Is stored, if any. If the clipboard is empty, the resulting string variable will also be empty.

There is one more way to store text or graphics in the clipboard. I’m not sure that there is a good reason to want to do this though. Using a screen GET, a portion of the screen can be copied into a non-string variable array. This variable can be written to the clipboard for later use. You can then read the clipboard and use a screen PUT, to place the data back on the screen. The screen GET and PUT commands are much more useful in moving sections of the screen image. Since the array used is not a string, it is not in the proper format for MacPaint or for PICTURE statements. I tried to use screen GET and PUT to read the picture of Professor Mac found in last month’s Screen Poke article. The problem is that when the image is directly poked on the screen, BASIC doesn’t recognize it as being anything useful. You can’t record pokes with the PICTURE ON/OFF feature of BASIC. Perhaps one of our readers knows how to change the data from a screen GET format to MacPaint picture format. For most programs you will want to use the other methods mentioned anyway.

In conclusion, figure 1 shows the different ways that data can be stored in the clipboard. Most of these methods are explained fairly well in the BASIC 2.0 manual. (ref. pg. 55-58 for more information on tranfering data between BASIC and other programs. Note there is an error on page 58 where it says PICTURE$,IMAGE$ should be PICTURE, IMAGE$. Also see pg. 205 for PICTURE statement.)

‘     Show Clip
‘     By Dave Kelly
‘     ©MACTUTOR 1985

‘Set up windows
WINDOW 1,”Output Window”, (2,40)-(510,200),1
WINDOW 2,”Clipboard File”,  (2,220)-(510,340),1
WINDOW CLOSE 2
‘Set up menus
MENU 4,0,0,””
MENU 5,0,1,”Windows”
MENU 5,1,1,”Output Window”
MENU 5,2,1,”Show Clipboard”
MENU 5,3,1,”Quit”
ON MENU GOSUB handlemenu
MENU ON
ON DIALOG GOSUB handlewindow
DIALOG ON
EDIT FIELD 1,””,(150,42)-(365,120),1
show:GOTO show:GOSUB showclipboard
handlemenu:  ‘Menu handler
number=MENU(0)
IF number<>5 THEN RETURN
item=MENU(1):MENU
IF item=1 THEN WINDOW 1
IF item=2 THEN GOSUB showclipboard
IF item=3 THEN WINDOW CLOSE 2:WINDOW CLOSE 1:MENU RESET: END
RETURN
handlewindow:  ‘Menu handler
stat=DIALOG(0)
IF stat=3 THEN WINDOW DIALOG(3)
IF stat=4 THEN WINDOW CLOSE DIALOG(4)
RETURN
showclipboard:
WINDOW 2:CLS
DIALOG STOP:MENU STOP
‘Read text from clipboard
OPEN “CLIP:TEXT” FOR INPUT AS #1
IF LOF(1)=0 THEN CLOSE #1:GOTO   do.picture
LOCATE 1,1
WHILE NOT EOF(1)
        INPUT #1,a$:PRINT a$
WEND
CLOSE #1:DIALOG ON:MENU ON
RETURN
do.picture:  ‘Read picture from Clipboard
DIALOG STOP:MENU STOP
OPEN “CLIP:PICTURE” FOR INPUT AS #1
        image$=INPUT$(LOF(1),1)
        PICTURE,image$
CLOSE #1:DIALOG ON:MENU ON:RETURN

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Dropbox 193.4.5594 - Cloud backup and sy...
Dropbox is a file hosting service that provides cloud storage, file synchronization, personal cloud, and client software. It is a modern workspace that allows you to get to all of your files, manage... Read more
Google Chrome 122.0.6261.57 - Modern and...
Google Chrome is a Web browser by Google, created to be a modern platform for Web pages and applications. It utilizes very fast loading of Web pages and has a V8 engine, which is a custom built... Read more
Skype 8.113.0.210 - Voice-over-internet...
Skype is a telecommunications app that provides HD video calls, instant messaging, calling to any phone number or landline, and Skype for Business for productive cooperation on the projects. This... Read more
Tor Browser 13.0.10 - Anonymize Web brow...
Using Tor Browser you can protect yourself against tracking, surveillance, and censorship. Tor was originally designed, implemented, and deployed as a third-generation onion-routing project of the U.... Read more
Deeper 3.0.4 - Enable hidden features in...
Deeper is a personalization utility for macOS which allows you to enable and disable the hidden functions of the Finder, Dock, QuickTime, Safari, iTunes, login window, Spotlight, and many of Apple's... Read more
OnyX 4.5.5 - Maintenance and optimizatio...
OnyX is a multifunction utility that you can use to verify the startup disk and the structure of its system files, to run miscellaneous maintenance and cleaning tasks, to configure parameters in the... Read more
Hopper Disassembler 5.14.1 - Binary disa...
Hopper Disassembler is a binary disassembler, decompiler, and debugger for 32- and 64-bit executables. It will let you disassemble any binary you want, and provide you all the information about its... Read more
WhatsApp 24.3.78 - Desktop client for Wh...
WhatsApp is the desktop client for WhatsApp Messenger, a cross-platform mobile messaging app which allows you to exchange messages without having to pay for SMS. WhatsApp Messenger is available for... Read more
War Thunder 2.33.0.135 - Multiplayer war...
In War Thunder, aircraft, attack helicopters, ground forces and naval ships collaborate in realistic competitive battles. You can choose from over 1,500 vehicles and an extensive variety of combat... Read more
Iridient Developer 4.2 - Powerful image-...
Iridient Developer (was RAW Developer) is a powerful image-conversion application designed specifically for OS X. Iridient Developer gives advanced photographers total control over every aspect of... Read more

Latest Forum Discussions

See All

A Legitimate Massage Parlor, I Swear – T...
In this week’s Episode of The TouchArcade Show we talk about some of the major new releases on mobile this week including Warframe, we go over all the major news that came out from the Nintendo Direct Partner Showcase on Wednesday, we read our one... | Read more »
TouchArcade Game of the Week: ‘Rainbow S...
I feel like I am in a fever dream right now. What is this game that I’m playing? It’s a Rainbow Six game? But it’s all cutesy, and cartoony, and also kind of psychedelic? How is this a real thing? Well, it’s no fever dream, it is indeed a real thing... | Read more »
SwitchArcade Round-Up: ‘Promenade’, ‘Cho...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for February 23rd, 2024. It’s Friday, so we have to check out the remaining releases of the week. Not so many big ones today, but a healthy crop nonetheless. After summarizing all the... | Read more »
Steam Deck Weekly: Gundam Breaker 4 and...
Welcome to this week’s slightly shorter edition of the Steam Deck Weekly. I was a bit unwell this week so no reviews in this edition, but there is a lot of news and new Steam Deck Verified and Playable games to catch up on. I have something special... | Read more »
The 10 Best Run-And-Gun Games for Ninten...
The year 2024 is a rare one, because it is a year with a brand-new Contra game. Contra: Operation Galuga might be the freshest face on the block when it comes to Nintendo Switch run-and-gun action games, but it’s hardly fighting that war alone.... | Read more »
Version 1.4 of Reverse: 1999 will be lan...
Free up your diary for February 29th, as Bluepoch has announced the impending release of the award-winning Reverse: 1999s Version 1.4 update. The Prisoner in the Cave is an Ancient Greece-themed update with new recruits, gameplay modes, and plenty... | Read more »
Premium Mobile RPG ‘Ex Astris’ From ‘Ark...
Arknights developer Hypergryph’s premium RPG Ex Astris () recently had its release date confirmed, and we finally have an extended gameplay showcase. | Read more »
Apple Arcade Weekly Round-Up: Updates fo...
Following yesterday’s big Hello Kitty Island Adventure update, a few more notable game updates and events have gone live on Apple Arcade. Cypher 007 () has gotten its first content update in a few months taking you to Egypt for five new levels... | Read more »
‘Thunder Ray’ and ‘Hime’s Quest’ Are Now...
Crunchyroll has pushed two new games into the Crunchyroll Game Vault including Purple Tree Studio’s Thunder Ray which was already on iOS before as a premium release. Shaun even reviewed it last year. Read his review here. The second game is Poppy... | Read more »
Adorable Kitty-Collector Sequel ‘Neko At...
Ya’ll. This October will mark the ten-year anniversary of Hit Point launching Neko Atsume, the adorable kitty collecting sim that has become a runaway success and essentially created a sub-genre of cozy pet-collecting life sim games. Sure, the... | Read more »

Price Scanner via MacPrices.net

16-inch M3 Max MacBook Pro on sale for $300 o...
Amazon is offering a $300 instant discount on one of Apple’s 16″ M3 Max MacBook Pros today. Shipping is free: – 16″ M3 Max MacBook Pros (36GB/1TB/Space Black): $3199, $300 off MSRP Their price is the... Read more
Apple M2 Mac minis on sale for $100 off MSRP...
B&H Photo has Apple’s M2-powered Mac minis in stock and on sale for $100 off MSRP this weekend with prices available starting at $499. Free 1-2 day shipping is available to most US addresses: –... Read more
Apple Watch SE on sale for $50 off MSRP this...
Best Buy has all Apple Watch SE models on sale this weekend for $50 off MSRP on their online store. Sale prices available for online orders only, in-store prices may vary. Order online, and choose... Read more
Deal Alert! Apple 15-inch M2 MacBook Airs on...
Looking for the lowest sale price on a new 15″ M2 MacBook Air? Best Buy has Apple 15″ MacBook Airs with M2 CPUs in stock and on sale today for $300 off MSRP on their online store. Prices valid for... Read more
Amazon discounts iPad mini 6 models up to $12...
Amazon is offering Apple’s 8.3″ WiFi iPad minis for $100-$120 off MSRP, including free shipping, for a limited time. Prices start at $399. Amazon’s prices are among the lowest currently available for... Read more
Apple AirPods Pro with USB-C discounted to $1...
Walmart has Apple’s 2023 AirPods Pro with USB-C in stock and on sale for $199.99 on their online store. Their price is $50 off MSRP, and it’s currently one the lowest prices available for new AirPods... Read more
Apple has 14-inch M3 MacBook Pro with 16GB of...
Apple has 14″ M3 MacBook Pros with 16GB of RAM, Certified Refurbished, available for $270-$300 off MSRP. Each model features a new outer case, shipping is free, and an Apple 1-year warranty is... Read more
Save $318-$432 on 16-inch M3 Max MacBook Pros...
Apple retailer Expercom has 16″ M3 Max MacBook Pros on sale for $318-$432 off MSRP when bundled with a 3-year AppleCare+ Protection Plan. Discounts are available for Silver models as well a Space... Read more
New today at Apple: 16-inch M3 Pro/M3 Max Mac...
Apple is now offering 16″ M3 Pro and M3 Max MacBook Pros, Certified Refurbished, starting at $2119 and ranging up to $530 off MSRP. Each model features a new outer case, shipping is free, and an... Read more
Apple is now offering $300-$480 discounts on...
Apple is now offering 14″ M3 Pro and M3 Max MacBook Pros, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is free, and an... Read more

Jobs Board

Part-time *Apple* and Peach Research Assist...
…and minimum qualifications: + Assist with planting, pruning, and harvesting of apple and peach trees + Conduct regular maintenance tasks to ensure optimal Read more
Housekeeper, *Apple* Valley Villa - Cassia...
Apple Valley Villa, part of a senior living community, is hiring entry-level Full-Time Housekeepers to join our team! We will train you for this position and offer a Read more
Sublease Associate Optometrist- *Apple* Val...
Sublease Associate Optometrist- Apple Valley, CA- Target Optical Date: Feb 22, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92307 **Requisition Read more
Sublease Associate Optometrist- *Apple* Val...
Sublease Associate Optometrist- Apple Valley, CA- Target Optical Date: Jan 24, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92307 **Requisition Read more
Housekeeper, *Apple* Valley Village - Cassi...
Apple Valley Village Health Care Center, a senior care campus, is hiring a Part-Time Housekeeper to join our team! We will train you for this position! In this role, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.