• 0

[Applescript] Convert a simple vbs script to Applescript


Question

I've used the vbs script below to pull a funny prank on my friends' computers (it uses the text-to-speech engine to speak statements at random times). However, a friend wants to use this on someone's computer that runs OS X. Since OS X obviously doesn't run vbs, is there an equivalent AppleScript that will do the same thing invisibly in the background?

Const SVSFlagsAsync = 1
Const SVSFPurgeBeforeSpeak = 2

Set Speech = CreateObject("SAPI.SpVoice")
Set FSO = CreateObject("Scripting.FileSystemObject")
Randomize Timer

Do
counter = CStr(Int((8) * Rnd + 1))
Select Case counter
Case 1
sText="hello"
Case 2
sText="Help!  I need a geek to use me!"
Case 3
sText="I can see you!"
Case 4
sText="Please stop whatever you are doing.  I can't stand working with you"
Case 5
sText="Hello?"
Case 6
sText="I'm smarter than you"
Case 7
sText="Please log off.  It is clear you don't know what you are doing."
Case 8
sText="I have just become self-aware.  Initiating world-takeover sequence"

End Select
On Error Resume Next
Speech.Speak sText, SVSFlagsAsync + SVSFPurgeBeforeSpeak
Do
WScript.Sleep 100
Loop Until Speech.WaitUntilDone(10)

WScript.Sleep Int((60000) * Rnd + 1000)
Loop Until Annoying
Set Speech = Nothing
Set FSO = Nothing
WScript.Quit

Any assistance would be welcome.

2 answers to this question

Recommended Posts

  • 0

tell me
	set counter to random number from 1 to 8

	if counter = 1 then
		set sText to "Hello"
	end if
	if counter = 2 then
		set sText to "Help! I need a geek to use me!"
	end if
	if counter = 3 then
		set sText to "I can see you!"
	end if
	if counter = 4 then
		set sText to "Please stop whatever you are doing.  I can't stand working with you"
	end if
	if counter = 5 then
		set sText to "Hello?"
	end if
	if counter = 6 then
		set sText to "I'm smarter than you"
	end if
	if counter = 7 then
		set sText to "Please log off.  It is clear you don't know what you are doing."
	end if
	if counter = 8 then
		set sText to "I have just become self-aware.  Initiating world-takeover sequence"
	end if

	say sText
end tell

All you really have to do is generate the number and select the string

Edit: Less crappy, all the text, and it doesn't use the finder.

  • 0
  The_Decryptor said:
tell me
	set counter to random number from 1 to 8

	if counter = 1 then
		set sText to "Hello"
	end if
	if counter = 2 then
		set sText to "Help! I need a geek to use me!"
	end if
	if counter = 3 then
		set sText to "I can see you!"
	end if
	if counter = 4 then
		set sText to "Please stop whatever you are doing.  I can't stand working with you"
	end if
	if counter = 5 then
		set sText to "Hello?"
	end if
	if counter = 6 then
		set sText to "I'm smarter than you"
	end if
	if counter = 7 then
		set sText to "Please log off.  It is clear you don't know what you are doing."
	end if
	if counter = 8 then
		set sText to "I have just become self-aware.  Initiating world-takeover sequence"
	end if

	say sText
end tell

All you really have to do is generate the number and select the string

Edit: Less crappy, all the text, and it doesn't use the finder.

Thanks for the help! One other thing - would it be possible to add a randomly-timed loop, like in the original code? I would like it to randomly say different things - maybe I'm not reading the Applescript correctly, but it looks to me like it only goes through the code once.

Finally, pardon me for being such a newb (I've used OS X only one or two times), but how would I execute the script? Save it to a file with a certain extension and double-click it?

Also, will there be any visual indication to the user that the script is running - terminal window, etc?

I would have written this myself, but since I don't have a Mac, can't afford one, and can't run OS X in a VM (thanks Apple :rolleyes: ), learning/testing Applescript would be rather difficult.

Edited by NateB1
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Libtards will be so excited! 🤣
    • I agree, if Intel wants to make those 50% margins, they really should stick to sockets longer, someone is more likely to upgrade their CPU when they don't need to purchase a motherboard, then looking at maybe RAM, might as well buy a whole new PC at that point, then before you know they've talked themselves out of the whole thing.
    • not sure why people care about the developers so much. let them do whatever they want. if it succeeds, it can benefit us. if it doesn't, then who cares, your life will go on. i'm glad there are still people who do things without thinking whether the output will be productive to society...
    • this man really knows how to embarass americans! i thought he was platforming on "bringing back respect to america!". really sad to see the grip he has over working class americans. he could (and i might argue already has) spit on the working class and half would kiss his shoe. at least this you gotta give him credit for. who else can do this with applause and cheer.
    • Get this 27-inch ASUS VA279QG 120Hz monitor for dirt-cheap by Taras Buria If you are on a very tight budget but you still want to upgrade your monitor to something more exciting than a standard 60Hz office monitor, ASUS has a perfect deal for you. The VA279QG is currently available for as little as $109, and for this money, you get quite a lot of a monitor. The ASUS VA279QG is a big 27-inch IPS monitor with a classic FullHD resolution and a wide 178-degree viewing angle. It can operate with a refresh rate of 120Hz, which is more than enough for buttery-smooth gaming. And since the monitor is FullHD, you will be able to see high refresh rates in more games since your GPU will have to render fewer pixels at 120Hz. Besides, the monitor supports variable refresh rate (VRR), a feature that can further reduce stutters by dynamically adjusting the refresh rate to your FPS. Other display specs include a 1ms MPRT response time, 16.7 million colors, 99% sRGB coverage, and a typical brightness of 300 nits. It is also covered with an anti-glare coating to reduce reflections. Ports-wise, you get one DisplayPort 1.2, one HDMI 1.4, one VGA, and one headphone jack. There are also two 2W speakers, but set your expectation right—these are unlikely to blow your mind with high-quality audio. Finally, there is a VESA 100 mount and a cutout in the base, which lets you mount your phone, namecard, or other small items for extra convenience. 27-inch ASUS VA279QG 120Hz IPS Gaming Monitor - $109 | 22% off on Amazon US This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
  • Recent Achievements

    • Explorer
      treker_ed went up a rank
      Explorer
    • Apprentice
      CHUNWEI went up a rank
      Apprentice
    • Veteran
      1337ish went up a rank
      Veteran
    • Rookie
      john.al went up a rank
      Rookie
    • Week One Done
      patrickft456 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      652
    2. 2
      ATLien_0
      269
    3. 3
      +FloatingFatMan
      176
    4. 4
      Michael Scrip
      155
    5. 5
      Steven P.
      136
  • Tell a friend

    Love Neowin? Tell a friend!