Jump to content

Really newbie question on my first workflow


Recommended Posts

Hi, 

I'm trying to create my first workflow; basically I assigned a shortcut key to open an app; ok that worked..

now I would like to add one step, after opening the app I would like the system to perform "Cmd+N", to create a new file in the app that I just opened.

 

So basically it would be: I press a shortcut key and alfred would open the app and create  a new file.

 

Is this possible, or there is maybe a better way to do that instead?

 

sorry for the really really newbie question, if you have any suggestion about that it would be great anyway

Link to comment

It is possible with AppleScript. In general, it is a very bad idea to script key presses, though, as it is imprecise and can lead to unforeseen results. The best option is to see in the app’s AppleScript dictionary if it has an option to create a new file (open Script Editor, do FileOpen Dictionary…).

However, if the only option is indeed emulating key presses (again, not recommended), you could do it also in AppleScript with something like tell application "System Events" to keystroke "n" using {command down}.

Link to comment
  • 2 weeks later...

thanks for the suggestion Vitor, not having any scripting knowledge I managed to solve it doing like this: in automator I recorded the action that I was doing, -open the app and click on new file. Then in alfred I created a shortcut to play the automator actions. 

It works, though I'm sure that there are better ways to do that

Link to comment

I saw that the method I used is not working well, often it gives me an error. I tried looking in the script dictionary, but the app doesn't have a command do create a new document, the only things showing up are:

 

windown : A window.

elements

contained by application.

properties

name (text, r/o) : The title of the window.

id (integer, r/o) : The unique identifier of the window.

index (integer) : The index of the window, ordered front to back.

bounds (rectangle) : The bounding rectangle of the window.

closeable (boolean, r/o) : Does the window have a close button?

miniaturizable (boolean, r/o) : Does the window have a minimize button?

miniaturized (boolean) : Is the window minimized right now?

resizable (boolean, r/o) : Can the window be resized?

visible (boolean) : Is the window visible right now?

zoomable (boolean, r/o) : Does the window have a zoom button?

zoomed (boolean) : Is the window zoomed right now?

document (document, r/o) : The document whose contents are displayed in the window.

responds to

close, print, save.

 

 

documentn: A document.

elements

contained by application.

properties

name (text, r/o) : Its name.

modified (boolean, r/o) : Has it been modified since the last save?

file (file, r/o) : Its location on disk, if it has one.

responds to

close, print, save.

 

 

I tried with this:  

tell application "iA Writer"

    activate
    make new document
end tell

 

but it is not working.. 

 

then I tried with this: 

 

tell application "iA Writer"

         activate

         keystroke "n" using {command down}

end tell

 

 

but it isn't working.. if somebody has any suggestion.. 

Edited by salmone
Link to comment

yup! thanks Vitor, I was able to achieve it, I did like this:

 

tell application "iA Writer"

activate

 

end tell

 

delay 0.2

 

tell application "System Events" to keystroke "n" using {command down}

 

 

I added the delay because I saw that without it often it was performing the cmd N when the active application wasn't IA writer yet, 

it seems to work really well, I'll test if everything keeps working fine in these days

Edited by salmone
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...