Jump to content
Urs Schwaller

Applescript not working in workflow anymore

Recommended Posts

Hi everybody

I'm really new to writing alfred workflows and also to applescript and I'm stuck ... I wrote a really small and simple script to write from alfred to the messaging app "Telegram". The script works fine when I run it in the Script editor but when I run it in Alfred I get the following Error:

[ERROR: alfred.workflow.action.applescript] {
    NSAppleScriptErrorBriefMessage = "Expected \U201cend\U201d but found \U201con\U201d.";
    NSAppleScriptErrorMessage = "Expected \U201cend\U201d but found \U201con\U201d.";
    NSAppleScriptErrorNumber = "-2741";
    NSAppleScriptErrorRange = "NSRange: {20, 2}";
}

Here is my AppleScript:

on alfred_script(q)

on ApplicationIsRunning(appName)
    tell application "System Events" to set appNameIsRunning to exists (processes where name is appName)
    return appNameIsRunning
end ApplicationIsRunning

if ApplicationIsRunning("Telegram") then
    tell application "Telegram" to quit
    delay 0.1
    tell application "Telegram" to activate
    delay 0.1
    tell application "System Events" to tell process "Telegram" to keystroke "Test"
    delay 0.1
    tell application "System Events" to tell process "Telegram" to keystroke (ASCII character 31)
else
    tell application "Telegram" to activate
    delay 0.1
    tell application "System Events" to tell process "Telegram" to keystroke "Test"
    delay 0.1
    tell application "System Events" to tell process "Telegram" to keystroke (ASCII character 31)
end if

end alfred_script

I guess it's a stupid mistake for you guys but I'm really stuck and haven't found anything online to solve it :/

 

 

Share this post


Link to post

solved it myself! sorry for the post! :/

 

solution was to put "ApplicationIsRunning" outside of "alfred_script"

on ApplicationIsRunning(appName)
	tell application "System Events" to set appNameIsRunning to exists (processes where name is appName)
	return appNameIsRunning
end ApplicationIsRunning

on alfred_script(q)


if ApplicationIsRunning("Telegram") then
	tell application "Telegram" to quit
	delay 0.1
	tell application "Telegram" to activate
	delay 0.1
	tell application "System Events" to tell process "Telegram" to keystroke "Test"
	delay 0.1
	tell application "System Events" to tell process "Telegram" to keystroke (ASCII character 31)
else
	tell application "Telegram" to activate
	delay 0.1
	tell application "System Events" to tell process "Telegram" to keystroke "Test"
	delay 0.1
	tell application "System Events" to tell process "Telegram" to keystroke (ASCII character 31)
end if

end alfred_script

Share this post


Link to post
Guest
This topic is now closed to further replies.
×
×
  • Create New...