You would have to pass the names or ids to the script, not simply emote them prior to calling the API command. For example, your macro might be: /emas @{selected|token_name} attacks @{target|token_name}! !script @{selected|token_id} @{target|token_id} Then, your script might be: on('chat:message', function(msg) { // Do nothing for messages which aren't API commands if (msg.type != 'api') return; // Each parameter in the API command is separated by a space, and the first part is the command itself var parts = msg.content.split(' '); // I like to remove the exclamation point at the start of the command name, but it's not required var command = parts.shift().substring(1); // Don't run your API command logic if some other command was sent! if (command == 'script') { // Make sure enough parameters were sent, to avoid index out of bounds if (parts.length < 2) { sendChat('SYSTEM', 'You must provide a selected token id and a target token id.'); return; } // Assume the first two parameters are object IDs var selectedId = parts[0]; var targetId = parts[1]; // Attempt to get the objects as graphics var selectedToken = getObj('graphic', selectedId); var targetToken = getObj('graphic', targetId); // If the objects *aren't* graphics, or the parameters weren't IDs, fail gracefully if (!selectedToken) { sendChat('SYSTEM', 'Selected token id not provided.'); return; } if (!targetToken) { sendChat('SYSTEM', 'Target token id not provided.'); return; } // Get a variable to use as the "who" for sendChat var who = getObj('character', selectedToken.get('represents')); if (!who) { who = selectedToken.get('name'); } else { who = 'character|' + who.id; } // Add script logic here. If the selected token represents a character in the journal, using `who' // as the first parameter to sendChat will post as that character. Otherwise, the chat will simply // use the token's name. sendChat(who, '/me does a thing to ' + targetToken.get('name') + '!'); } }); I hope that helps.