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
‘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
ON DIALOG GOSUB handlewindow
EDIT FIELD 1,””,(150,42)-(365,120),1
show:GOTO show:GOSUB showclipboard
handlemenu:  ‘Menu handler
IF number<>5 THEN RETURN
IF item=2 THEN GOSUB showclipboard
handlewindow:  ‘Menu handler
‘Read text from clipboard
IF LOF(1)=0 THEN CLOSE #1:GOTO   do.picture
        INPUT #1,a$:PRINT a$
do.picture:  ‘Read picture from Clipboard


Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Can PokeMatch help you find love with Po...
The unofficial Pokemon GO companion app space has exploded almost as fast as the game itself over the last few weeks. Aspiring app developers, many of them working solo, have given us apps that locate Pokemon, keep track of the server status, and... | Read more »
How to get started with Prisma
If there's one thing people like to do more than taking pictures with their smartphones, it's tinkering with those photos in some way. Numerous apps have sprung up over the last several years that allow you to use filters and special effects to... | Read more »
6 Pokemon GO updates you can expect, acc...
Pokemon GO had a scheduled appearance at this year's San Diego Comic-Con for a while, but it was only relatively close to the show that it was upgraded to a spot in Hall H. That's the biggest venue at SDCC, one usually reserved for the largest... | Read more »
How to evolve Eevee in Pokemon GO
By now, almost everyone should be hip to how to evolve Pokemon in Pokemon GO (and if not, there's a guide for that). Just gather enough candy of the appropriate type, feed them all to the Pokemon, and evolution happens. It's a miracle that would... | Read more »
CSR Racing 2: Guide to all game modes
It might not seem like there are all that many ways to go fast in a straight line, but CSR Racing 2 begs to differ. [Read more] | Read more »
Bulb Boy (Games)
Bulb Boy 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Multi-award winning 2D point & click horror adventure about a boy with a glowing head. | Read more »
5 top free emoji keyboard apps
If we're not at peak emoji yet as a society, it feels like we definitely should be. The emoji concept has gone far beyond what anyone in Japan could have envisioned when the people there unleashed it on an unsuspecting world, but the West has... | Read more »
How to unlock more characters in Disney...
One of the big charms of Disney Emoji Blitz is seeing a wide variety of beloved Disney and Pixar characters transformed into smiling emojis. Even someone like the sneaky Randall from Monsters Inc., who probably never cracked a smile on film, is... | Read more »
Cubway (Games)
Cubway 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Cubway is a journey with an abstract story of lifecycle of rebirth, called Samsara. Guide the cube through the long way full of dangers... | Read more »
Colorcube (Games)
Colorcube 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Turn pieces and blend colours in this minimal yet visually stunning puzzler.Over 200 handcrafted and challenging levels. Features... | Read more »

Price Scanner via

Apple’s 2016 Back to School promotion: Free B...
Purchase a new Mac or iPad using Apple’s Education Store and take up to $300 off MSRP. All teachers, students, and staff of any educational institution qualify for the discount. Shipping is free, and... Read more
Apple refurbished iPad Air 2s available start...
Apple has Certified Refurbished iPad Air 2 available starting at $339. Apple’s one-year warranty is included with each model, and shipping is free: - 128GB Wi-Fi iPad Air 2: $499 - 64GB Wi-Fi iPad... Read more
13-inch 2.5GHz MacBook Pro available for $964...
Overstock has the 13″ 2.5GHz MacBook Pro available for $964.21 including free shipping. Their price is $135 off MSRP. Read more
External Keyboard Innovations For iPad Pro (1...
I’m an input device aficionado. With non-touchscreen computers, which includes all Macs, the keyboard and mouse or trackpad are the tactile points of interface between user and machine, and the... Read more
GSK Rheumatoid Arthritis Study Leverages iPho...
Global healthcare products company GlaxoSmithKline (GSK) says that since 2014 they have begun transforming the way they conduct research, by leveraging state-of-the-art digital technologies — a... Read more
Clearance 12-inch Retina MacBooks, Apple refu...
Apple has Certified Refurbished 2015 12″ Retina MacBooks available starting at $929. Apple will include a standard one-year warranty with each MacBook, and shipping is free. The following... Read more
13-inch Retina MacBook Pros on sale for up to...
B&H Photo has 13″ Retina MacBook Pros on sale for up to $150 off MSRP. Shipping is free, and B&H charges NY tax only: - 13″ 2.7GHz/128GB Retina MacBook Pro: $1199 $100 off MSRP - 13″ 2.7GHz/... Read more
13-inch 1.6GHz/128GB MacBook Air on sale for...
Amazon has the 13″ 1.6GHz/128GB MacBook Air on sale for $200 off MSRP for a limited time. Shipping is free: - 13″ 1.6GHz/128GB MacBook Air (sku MMGF2LL/A): $799.99 $200 off MSRP Their price is the... Read more
13-inch 1.6GHz/256GB MacBook Air on sale for...
Amazon has the 13″ 1.6GHz/256GB MacBook Air on sale for $200 off MSRP for a limited time. Shipping is free: - 13″ 1.6GHz/256GB MacBook Air (sku MMGG2LL/A): $999.99 $200 off MSRP Their price is the... Read more
Free iOS Business App notably* Helps Service...
PayStudio Inc. has introduced their new business app notably* 1.0, developed for iPhone and iPod touch. notably* was specifically developed to help service and trade professionals go digital and... Read more

Jobs Board

*Apple* Retail - Multiple Positions, Willow...
Job Description:SalesSpecialist - Retail Customer Service and SalesTransform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* Evangelist - JAMF Software (United S...
The Apple Evangelist is responsible for building and cultivating strategic relationships with Apple 's small and mid-market business development field teams. This Read more
*Apple* Solutions Consultant - APPLE (United...
Job Summary As an Apple Solutions Consultant, you'll be the link between our future customers and our products. You'll showcase your entrepreneurial spirit as you Read more
*Apple* Professional Learning Specialist - A...
Job Summary The Apple Professional Learning Specialist is a full-time position for one year with Apple in the Phoenix, AZ area. This position requires a high Read more
*Apple* Picker - Apple Hill Orchard (United...
Apple Hill Orchard, Co. Rte. 21,Whitehall, NY 9/7/16-10/228/16. Pick fresh market or processing apples Productivity of 60 boxes and 80 boxes processing fruit per Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.