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 Apr 17, 2008, 12:43 AM   #1
thriftinkid
macrumors regular
 
Join Date: Mar 2008
Script Editor to Automator Issue

I have had a few scripts now that work fine when I run the in script editor, but they don't run properly in automator. Automator has the ability to run applescript as part of a work flow by copying as pasting your applescript directly into Automator. I haven't had errors everytime I do it. But there are certain scripts that have had errors that have forced me to do some adjustments. Any ideas why? This recent script gave me the following error after copying and pasting it into an automator workflow.

Syntax Error
No result was returned from some part of this expression.


Here is the script:

(including automators on run, return input, and end tell commands added by automator within workflow.)

Code:
on run {input, parameters}
	
	tell application "Finder"
		set theFolder to "Macintosh HD:Users:John:Desktop:Finished" as alias
		set theList to name of (every file in theFolder)
	end tell
	
	repeat with i from 1 to (number of items of theList)
		set theName to (item i of theList)
		set item i of theList to ("http://www.mywebsite.com/mainfolder/" & theName)
	end repeat
	set theText to "

"
	repeat with i from 1 to (number of items of theList)
		set theText to (theText & (item i of theList) & "

")
	end repeat
	
	tell application "TextEdit"
		activate
		make new text document
		set the text of the front document to theText
		
	end tell
	
	return input
end run
thriftinkid is offline   0 Reply With Quote
Old Apr 17, 2008, 07:51 PM   #2
thriftinkid
Thread Starter
macrumors regular
 
Join Date: Mar 2008
Quote:
Originally Posted by thriftinkid View Post
I have had a few scripts now that work fine when I run the in script editor, but they don't run properly in automator. Automator has the ability to run applescript as part of a work flow by copying as pasting your applescript directly into Automator. I haven't had errors everytime I do it. But there are certain scripts that have had errors that have forced me to do some adjustments. Any ideas why? This recent script gave me the following error after copying and pasting it into an automator workflow.

Syntax Error
No result was returned from some part of this expression.


Here is the script:

(including automators on run, return input, and end tell commands added by automator within workflow.)

Code:
on run {input, parameters}
	
	tell application "Finder"
		set theFolder to "Macintosh HD:Users:John:Desktop:Finished" as alias
		set theList to name of (every file in theFolder)
	end tell
	
	repeat with i from 1 to (number of items of theList)
		set theName to (item i of theList)
		set item i of theList to ("http://www.mywebsite.com/mainfolder/" & theName)
	end repeat
	set theText to "

"
	repeat with i from 1 to (number of items of theList)
		set theText to (theText & (item i of theList) & "

")
	end repeat
	
	tell application "TextEdit"
		activate
		make new text document
		set the text of the front document to theText
		
	end tell
	
	return input
end run
It seemed it was having a particular problem with this part of the code, but I'm not sure:

Code:
repeat with i from 1 to (number of items of theList)
		set theText to (theText & (item i of theList) & "
thriftinkid is offline   0 Reply With Quote
Old Apr 17, 2008, 10:24 PM   #3
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
I have no idea, but getting the number of items in theList was no longer working. This seems to:

Code:
on run {input, parameters}
	
	tell application "Finder"
		set theFolder to "Macintosh HD:Users:lee:Desktop:Finished" as alias
		set theList to name of (every file in theFolder)
	end tell
	
	set theText to "

"

	repeat with theName in theList
		set theText to (theText & ("http://www.mynetwork.tv/vue/" & theName) & "
		
")
	end repeat
	
	set input to theText
	
	return input
	
end run
This passes the generated text to the next step in the automator workflow. That may not be what you want to do, but writing it to the text file is sort of a dead-end in the workflow, unless there's some way to tell the next step where a document is, etc.

-Lee
lee1210 is offline   0 Reply With Quote
Old Apr 17, 2008, 10:25 PM   #4
lancestraz
macrumors 6502a
 
lancestraz's Avatar
 
Join Date: Nov 2005
Location: RI
For some crazy reason, Automator doesn't like the phrase "number of items in" so use "count" instead. Also, the word "text" should be omitted from the line "make new text document" in the TextEdit block. Tweaked the TextEdit "make new document" code a bit so that if TextEdit is not active when this script is run it will not create two documents.

Code:
on run {input, parameters}
	
	tell application "Finder"
		set theFolder to "Macintosh HD:Users:John:Desktop:Finished" as alias
		set theList to name of (every file in theFolder)
	end tell
	
	repeat with i from 1 to (count theList)
		set theName to (item i of theList)
		set item i of theList to ("http://www.mywebsite.com/mainfolder/" & theName)
	end repeat
	set theText to "

"
	repeat with i from 1 to (count theList)
		set theText to (theText & (item i of theList) & "

")
	end repeat
	
	tell application "TextEdit"
		activate
		if (front document exists) = true then
			if (text of the front document) ≠ "" then
				make new document
			end if
		else
			make new document
		end if
		set the text of the front document to theText
	end tell
	
	return input
end run
lancestraz is offline   0 Reply With Quote
Old Jun 25, 2013, 09:24 AM   #5
axello
macrumors newbie
 
Join Date: Feb 2006
Location: Amsterdam
Quote:
Originally Posted by lancestraz View Post
For some crazy reason, Automator doesn't like the phrase "number of items in" so use "count" instead. Also, the word "text" should be omitted from the line "make new text document" in the TextEdit block. Tweaked the TextEdit "make new document" code a bit so that if TextEdit is not active when this script is run it will not create two documents.
Wow! That really saved my day. Sometimes (often?) these idiosyncrasies of Apple Script drive me crazy .

Thanks for giving us the solution!
axello 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
there HAS to be this itunes script available somewhere ... eroxx Mac Applications and Mac App Store 2 Aug 21, 2011 08:56 PM
looking for a specific automation/script for itunes ... > eroxx OS X 0 Jun 4, 2011 07:17 PM
Turning iMac G4 into a multimedia center and automation themacguy12 iMac 1 Dec 16, 2010 05:23 PM
Quicksilver script send to script editor instead of running Ztmpx Mac Basics and Help 0 Apr 26, 2008 09:46 AM
Install Script Editor, Automator and DVD Player satyam90 Mac Basics and Help 3 Mar 22, 2008 06:18 AM


All times are GMT -5. The time now is 07:30 PM.

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

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