Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 5, 2013, 10:06 PM   #1
moonman239
macrumors 65816
 
Join Date: Mar 2009
Applescript: How do I create custom data types?

Maybe the title was badly worded, but you'll understand what I mean after I explain what I want to do.

I want to make a script that creates multiple random, unique ID's. To accomplish this, I could do something like this:

Code:
on randomID()
--ID generation code
end randomID
set theid to randomID()
but I thought I could do something like this:

Code:
to randomID
--ID generation code
end randomID
set theID to randomID
Notice the lack of parentheses after "set theID to".

Somebody on a different forum was able to construct a method that would return a string with something in the string replaced with the value of another string. Here's his code:

Code:
to switchText from t to r instead of s
	set d to text item delimiters
	set text item delimiters to s
	set t to t's text items
	set text item delimiters to r
	tell t to set t to item 1 & ({""} & rest)
	set text item delimiters to d
	t
end switchText
When I tried the second block of code, AppleScript told me it expected something to follow "to randomID".

Any help would be greatly appreciated!
__________________
The funny thing about this signature is that by the time you get to the end of it, you will have spent between five and ten seconds doing so.

Last edited by moonman239; Jan 5, 2013 at 10:07 PM. Reason: Fixed a mistake in the second-to-last sentence.
moonman239 is offline   0 Reply With Quote
Old Jan 5, 2013, 11:07 PM   #2
Red Menace
macrumors 6502
 
Join Date: May 2011
Location: Littleton, Colorado, USA
When defining and calling handlers, you must include its parameters, even if there aren't any (in that case, you include a pair of empty parentheses after the handler name). The second form just uses labeled parameters instead of positional ones - see the Handler Basics section of the AppleScript Language Guide.
__________________
MacBook Pro / OS X Mavericks (10.9.4) / Xcode 5.1.1 / RubyMotion FTW
Red Menace is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
How to create sub-mailboxes with Applescript? torchy Mac Programming 14 May 29, 2014 04:21 PM
Applescript to create a smart folder for each tag? feijoada OS X Mavericks (10.9) 0 Mar 7, 2014 09:55 PM
create folders applescript joennie Mac Programming 3 Jul 30, 2013 06:43 PM
I want to make AppleScript Create Folder DavidBlack Mac Programming 27 Mar 15, 2013 06:18 PM
Use AppleScript to create a PPI Calculator? TheMTtakeover Mac Programming 1 Dec 26, 2012 10:11 AM

Forum Jump

All times are GMT -5. The time now is 09:24 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC