{"_id":"59d15afbf573d3001a20515c","project":"5746675a5aa03c0e00fce9bc","version":{"_id":"5746675a5aa03c0e00fce9bf","__v":8,"project":"5746675a5aa03c0e00fce9bc","createdAt":"2016-05-26T03:02:50.849Z","releaseDate":"2016-05-26T03:02:50.849Z","categories":["5746675a5aa03c0e00fce9c0","574899e7e8c6a420000b7314","57489c11d929e919006ed4ae","57489c82d929e919006ed4b1","57489ce91b345d0e004e5231","5748a82e1b345d0e004e5256","59ce5c88e8c105001a4bedd7","59f96cd129b4d600246c2899"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"59ce5c88e8c105001a4bedd7","project":"5746675a5aa03c0e00fce9bc","version":"5746675a5aa03c0e00fce9bf","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-09-29T14:45:28.177Z","from_sync":false,"order":1,"slug":"blockspring-scripts","title":"Blockspring Scripts"},"user":"545988354f86a50800f9cce4","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-10-01T21:15:39.616Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"Let's learn how to add App Buttons for running your script.\n[block:api-header]\n{\n  \"title\": \"Usecase: Count Cards\"\n}\n[/block]\nIn this tutorial, we'll add a button that counts the number of cards in a board, and adds the count to the board name.\n\nEnter the following code into your script:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import trello_app\\n\\ndef count_cards():\\n    # get old board name\\n    board = trello_app.get_current_board()\\n    old_board_name = board.get_name().split(\\\" [\\\")[0]\\n\\n    # get all open cards\\n    card_count = len(board.get_cards(filter=\\\"open\\\"))\\n\\n    # set board name with card counts\\n    board.set_name(\\\"%s [%s]\\\" % (old_board_name, card_count))\",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\n## Run the script from your editor\nWe can test this script by clicking the **Run** button as follows.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/261f3d5-test2.gif\",\n        \"test2.gif\",\n        1095,\n        598,\n        \"#2a8f88\"\n      ]\n    }\n  ]\n}\n[/block]\n## Using an App Button\n\nRather than only use the **Run** button in the editor, we can also close the editor and use an App Button.\n\nGo back to the app. Rather than clicking the Blockspring leaf to open the editor, hover and click on your function name (in this case `count_cards`).\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/85024e8-button.gif\",\n        \"button.gif\",\n        929,\n        591,\n        \"#50b56d\"\n      ],\n      \"border\": true\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Need Help?\"\n}\n[/block]\nIf you run into any issues, or what to chat with others, [connect to the Blockspring community](https://blockspring-help.readme.io/docs/getting-help) right from the Scripts editor.","excerpt":"","slug":"tutorial-buttons","type":"basic","title":"Tutorial: App Buttons"}

Tutorial: App Buttons


Let's learn how to add App Buttons for running your script. [block:api-header] { "title": "Usecase: Count Cards" } [/block] In this tutorial, we'll add a button that counts the number of cards in a board, and adds the count to the board name. Enter the following code into your script: [block:code] { "codes": [ { "code": "import trello_app\n\ndef count_cards():\n # get old board name\n board = trello_app.get_current_board()\n old_board_name = board.get_name().split(\" [\")[0]\n\n # get all open cards\n card_count = len(board.get_cards(filter=\"open\"))\n\n # set board name with card counts\n board.set_name(\"%s [%s]\" % (old_board_name, card_count))", "language": "python" } ] } [/block] ## Run the script from your editor We can test this script by clicking the **Run** button as follows. [block:image] { "images": [ { "image": [ "https://files.readme.io/261f3d5-test2.gif", "test2.gif", 1095, 598, "#2a8f88" ] } ] } [/block] ## Using an App Button Rather than only use the **Run** button in the editor, we can also close the editor and use an App Button. Go back to the app. Rather than clicking the Blockspring leaf to open the editor, hover and click on your function name (in this case `count_cards`). [block:image] { "images": [ { "image": [ "https://files.readme.io/85024e8-button.gif", "button.gif", 929, 591, "#50b56d" ], "border": true } ] } [/block] [block:api-header] { "title": "Need Help?" } [/block] If you run into any issues, or what to chat with others, [connect to the Blockspring community](https://blockspring-help.readme.io/docs/getting-help) right from the Scripts editor.